jquery - highlight menu items based on associated content -


i using jquery display content on website based upon menu item selection. each menu item has number attached matches content div container.

    $(".main-cat").hover(function() {     $(this).parent().find("div.arrow-right").remove();     $(this).after('<div class="arrow-down"></div>');     $(this).addclass('selected');     $(this).css('cursor', 'pointer'); },     function() {     $(this).removeclass('selected');     $(this).parent().find("div.arrow-down").remove(); });  $("#sidebar div").click(function() {     $("#real_0").hide();     $(".content_sub").hide();     var menuclass = $(this).attr('class');     menuclassp = menuclass.split(" ");     $("#real_" + menuclassp[1]).fadein('slow'); }); 

i trying add function highlight menu item corresponds currently *active* content.

what's best way write this? , can current code made cleaner?

add

$(this).addclass('selected').siblings().removeclass('selected'); 

in click handler, , define selected class in css defines highlight style..

this add class selected clicked element (assuming active content), , remove siblings (the other divs in sidebar)


Comments

Popular posts from this blog

linux - Using a Cron Job to check if my mod_wsgi / apache server is running and restart -

actionscript 3 - TweenLite does not work with object -

jQuery Ajax Render Fragments OR Whole Page -