I need to bind the click function on each div of this ordered list in order to make hide/show an image on each imgXX div, I'm newbie with JQuery
<ol id='selectable'>
<li class="ui-state-default">
<div id="img01" class="img">
<div id="star01" class="star">
<img src="../ima/star.png" height="30px"/>
</div>
</div>
</li>
<li class="ui-state-default">
<div id="img02" class="img">
<div id="star02" class="star">
<img src="../ima/star.png" height="30px"/>
</div>
</div>
</li>
</ol>
JQuery
$('div').each(function(){
$(this).click(function(){
if($(this).find('img').is(':visible').length){
$(this).find('img').fadeOut(700);
}
else{
$(this).find('img').fadeIn(700);
}
});
});
Try this:
$('div').each(function(){
$(this).click(function(){
if($(this).find('img').is(':visible')){
$(this).find('img').fadeOut(700);
}
else{
$(this).find('img').fadeIn(700);
}
});
});
The is
method returns a boolean. Use:
if($(this).find('img').is(':visible'))
or:
if($(this).find('img:visible').length)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With