3

i dont know, how to chance this script to jQuery, please help JavaScript

function show_t(id){
    document.getElementById("hide_t_"+id).style.visibility='visible';
}
function hide_t(id){
    document.getElementById("hide_t_"+id).style.visibility='hidden';
}

this is div element on php, with above script

    <div class='item' onMouseOver="show_t('$dataBB[0]')" 
onMouseOut="hide_t('$dataBB[0]')">

I have trouble, when I change with this script

$("#show_t1"+id).mouseover(function(){
    document.getElementById("hide_t_"+id).style.visibility='visible';
}).mouseout(function(){
    document.getElementById("hide_t_"+id).style.visibility='hidden';
});

the div element for script on above is

<div id="show_t$dataBB[0]">
<span id='hide_t_$dataBB[0]' class='hide_input'>
</span>
</div>

You can see what I means in www.tumbasklik.com

4 Answers 4

4

Change

document.getElementById("hide_t_"+id).style.visibility='visible';

To

$("#hide_t_"+id).css('visibility','visible');

Your code would be.

$("#show_t1"+id).mouseover(function(){       
    $("#hide_t_"+id).css('visibility','visible');
}).mouseout(function(){       
    $("#hide_t_"+id).css('visibility','hidden');
});

Edit: You can change your selector to use wild cards instead of feeding id, and using class of span instead of generating the id.

Live Demo

$("[id^=show_t]").mouseover(function() {
    $(this).find('.hide_input').css('visibility', 'visible');
}).mouseout(function() {
    $(this).find('.hide_input').css('visibility', 'hidden');
});​
Sign up to request clarification or add additional context in comments.

7 Comments

how about the div element? <div id="show_t$dataBB[0]"> <span id='hide_t_$dataBB[0]' class='hide_input'> </span> </div>
You can use find() method of jQuery to select the elements with div like $("#hide_t_"+id).find('.hide_input') will give you span Read more about find here, api.jquery.com/find
@Arry: you'll have to give more than that if you want us to help you resolve the problem. How is it not working? Are there any errors in the JavaScript console? Is it just doing something differently than you want, or nothing at all?
Unless I'm mistaken, it could just be that the solution here needs to be in a document ready function since the variables in the div are provided from the PHP script.
@arttronics Now I understood what you meant with "populated by PHP". Past my sleep time already, sorry. Happy new year everyone btw.
|
2

Step By Step

  1. There is no need of onMouseOver and onMouseOut function in .item divs. Remove them. No need to pass values from php

  2. Make your spans meaningful - instead of putting class hide_item to all spans, put class as buy-option hidden. Do all the styles to .buy-option { /* Styles */ } and put .hidden { display: none; }

  3. Change jQuery code to this much only:

    jQuery(function($) {
        $('div.item').mouseover(function() {
            $(this).find('.buy-option').removeClass('hidden');
        })
        $('div.item').mouseout(function() {
            $(this).find('.buy-option').addClass('hidden');
        });
    });
    
  4. Check Working fiddle and copy paste code from respective iframes (HTML, CSS, JS)

  5. Start Learning jQuery starting from DOM traversal

2 Comments

thanks so much :), can you send your file to my email [email protected]
i have see in jsfiddle.net/OMS_/4CLAZ , its working . hahaha nice.... i love ya... thanks so much
0

with Jquery -

$("#hide_t_"+id).hide();
$("#hide_t_"+id).show();

Try like this-

$("#show_t1"+id).mouseover(function(){
    $(this).show();
}).mouseout(function(){
    $(this).hide();
});

demo

9 Comments

i have using this suresh, but its not useful -_-
@ArryanggaAlievPratamaputra: updated my post please try like this.
if is using $(this).show(), its didnt referer to anything id right?
@ArryanggaAlievPratamaputra: $(this) refer the same element. so i think it will work for you.
did you mean like this "$(this) is refer to all element id one group, i means in the inside div element"
|
0
$("#show_t1"+id).mouseover(function(){
    $("#hide_t_"+id).css('visibility','visible');
}).mouseout(function(){
    $("#hide_t_"+id).css('visibility','hidden');;
});

1 Comment

who have problem with answer

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.