what exactly is this.id ?

Posted by kwokwai on Stack Overflow See other posts from Stack Overflow or by kwokwai
Published on 2010-05-14T19:13:25Z Indexed on 2010/05/14 19:24 UTC
Read the original article Hit count: 239

Filed under:

Hi all,

I was doing some dynamic effect on DIV using JQuery when I found that
the returned value of this.id varied from function to function.

I got two sets of simple parent-child DIV tags like this:

        <DIV ID="row">
        <DIV ID="c1">              
        <Input type="radio" name="testing" id="testing" VALUE="1">testing1
        </DIV>
        </DIV> 
        <DIV ID="row">
        <DIV ID="c2">              
        <Input type="radio" name="testing" id="testing" VALUE="2">testing2
        </DIV>
        </DIV> 

Code 1.

$('#row DIV').mouseover(function(){ 
radio_btns.each(function() {
$('#row DIV).addClass('testing');  // worked
});
});


Code 2.

$('#row DIV').mouseover(function(){ 
var childDivID = this.id;
radio_btns.each(function() {
$('#'+childDivID).parent('DIV').addClass('testing');  // didn't work
});
});


I don't understand why only the first code couldn work
and highlighted all the "row" DIV,
but the first code failed to do so?

© Stack Overflow or respective owner

Related posts about jQuery