mardi 30 septembre 2014

Set active menu to current page by clicking any links outside nav menu


Vote count:

0




Both of the following codes are working.



$("li a").filter(function(){ return this.href == location.href.replace(/#.*/, ""); }).parents('nav ul li').addClass("selected");


and



var loc = window.location.href;
$("a").each(function() {
if(this.href == loc) {
$(this).parents('nav ul li').addClass('selected');
}
});


But my problem is you can only add class to links inside nav. Clicking any links outside the div wont add any class. Please take a look on this url and click link outside nav1 or 2.



  1. Which one do you recommend me to use?

  2. How to set a default class to the first li(videos) using jquery when I click any links outside nav area?


Please help me on this. Thank you!



asked 26 secs ago







Set active menu to current page by clicking any links outside nav menu

Aucun commentaire:

Enregistrer un commentaire