jquery find previous li and change css -
i'm trying write script allow me change css of previous li on hover.
here's structure:
<ul id="mainlevel"> <li><a href="/" class="mainlevel" id="active_menu">home</a></li> <li><a href="/" class="mainlevel">about us</a></li> <li><a href="/" class="mainlevel">products</a></li> <li><a href="/" class="mainlevel">projects</a></li> <li><a href="/" class="mainlevel">suppliers</a></li> </ul>
here's have far:
jquery("#mainlevel li a").hover(function() { jquery(this).prev("li a").css("background", "#f0f"); });
but it's not working.. appreciated :)
the following seems work:
$(document).ready( function() { $('li a').hover( function(){ $(this).parent().prev('li').css('background-color','#f0f'); } ); } );
albeit haven't removed background-colours when li
no longer hovered-over.
demo at: js bin.
Comments
Post a Comment