javascript - Add class to child that fits url -


i've made 1 page layout website, menu doesn't show active/current link, when users come google or bookmarked it.

i've made script works fine, see.... horribly. how can smart??

//set .active current page link     if (location.href.indexof("#2") != -1) {         $("#menu li:nth-child(1) ").addclass("active");     }     if (location.href.indexof("#3") != -1) {         $("#menu li:nth-child(2) ").addclass("active");     }     if (location.href.indexof("#4") != -1) {         $("#menu li:nth-child(3) ").addclass("active");     }     if (location.href.indexof("#5") != -1) {         $("#menu li:nth-child(4) ").addclass("active");     }     if (location.href.indexof("#6") != -1) {         $("#menu li:nth-child(5) ").addclass("active");     } 

thank in advance...

how like:

$("#menu li:nth-child(" + ( location.hash.slice(1) - 1 ) + ") ").addclass("active"); 

Comments

Popular posts from this blog

python - Scipy curvefit RuntimeError:Optimal parameters not found: Number of calls to function has reached maxfev = 1000 -

c# - How to add a new treeview at the selected node? -

java - netbeans "Please wait - classpath scanning in progress..." -