jquery - Change ul background when li is in hover or active state -
i have list, , need change background image of ul when hovering on each child. i've done using the code here (here i'm using color instead of background image).
now, if click on item 1 there's 'active' class dynamically added i'm taken .page-1. here need background show corresponding image (or yellow color, per example). tried css:
.page-1 #menu { background-color: yellow; } but color disappears hover on other items. think should use .hasclass method, i'm not jquery can't figure out.
any appreciated.
you can use style , class attribute @ same time. style attribute override color of class attribute.
<ul id="menu" style="background-color:yellow" class="pink"> on hover event add class #menu, on click event change style of #menu.
$('.item_1').hover(function() { $('#menu').addclass('yellow'); }, function() { $('#menu').removeclass('yellow'); }); $('.item_1').click(function() { $('#menu').css('background-color', 'yellow'); return false; }); here example jsfiddle
Comments
Post a Comment