javascript - Using server-side includes, what are options for selecting a current nav element? -


i'm using 10-item unordered list navigation bar. using ssi, put header , navigation bar every file. i'd way add class="active" ruleset of active page (the current page's corresponding <li> have different style).

including file in every page means that, in included file, none of items can have active class.

is there way in few lines of code? (using jquery/js)

my other option match last part of url part of href of anchor within each list item.

solution: (courtesy of romangorbatko)

var tab = window.location.pathname.split("/"); tab = tab[tab.length - 1];  // not efficient - suggestions? if (tab != "") $("#nav a#" + tab).addclass("active"); 

for example. hame pages:

and menu has next form:

<ul>     <li class="index">index</li>     <li class="faq">faq</li>     <li class="forum">forum</li> </ul> 

now check url of page.

var index = window.location.pathname.split('/')[1]; $('ul.li').removeclass('active'); $('li.' + index).addclass('active'); 

profit!


Comments

Popular posts from this blog

php - Calling a template part from a post -

Firefox SVG shape not printing when it has stroke -

How to mention the localhost in android -