Jquery image rollover on parent li hover -


i have responsive image based nav menu used jquery swap out rollover image.

<ul id="mainmenu">   <li><a href="#"><img src="nav1-off.png" class="rollover"/></a>       <div class="mega-menu"><p>mega menu content in here</p></div>   </li>      <li><a href="#"><img src="nav2-off.png" class="rollover"/></a>       <div class="mega-menu"><p>mega menu content in here</p></div>   </li> </ul>   $("img.rollover").hover(             function() { this.src = this.src.replace("-off", "-on");             },             function() { this.src = this.src.replace("-on", "-off");             }); 

how instead toggle image src when parent li hovered over.

basically need when newly added mega menu divs hovered on hover image still shows in menu. tried no luck -

$("img.rollover").parent().hover(     function() {     $("img.rollover",this).src = $("img.rollover",this).attr("src").replace("-off", "-on");     },     function() {     $("img.rollover",this).src = $("img.rollover",this).attr("src").replace("-on", "-off");     }); 

$("#mainmenu").on("mouseenter", "li", function(){     var rollover = $(this).find(".rollover")[0];     rollover.src = rollover.src.replace("-off", "-on"); }).on("mouseleave", "li", function(){     var rollover = $(this).find(".rollover")[0];     rollover.src = rollover.src.replace("-on", "-off"); }); 

example: http://jsfiddle.net/n5rcv/


Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

javascript - jQuery .height() return 0 when visible but non-0 when hidden -