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

Popular posts from this blog

ASP.NET/SQL find the element ID and update database -

jquery - appear modal windows bottom -

c++ - Compiling static TagLib 1.6.3 libraries for Windows -