javascript - Add class to active page does not work for pages in sub folders -


i have following script add class .active current page:

//main menu .active classes handler     $("#mainmenu a").filter(function () {         var href = location.href.replace(/#*/, "");         if (location.pathname === "/") {href += "index";}         return href === this.href;     }).addclass("active"); 

everything works fine pages in main directory not work pages in sub folders, example:

it works <a href="index.php">home</a> won't work for: <a href="sub/test.php">home</a> why that? need add "last of index"?

full hmtl:

<li><a href="index">home</a></li> <li><a href="about">about</a></li> <li class="submenu"><a href="gallery">gallery</a>     <ul>         <li><a href="sub/test">page in sub folder</a></li>     </ul> </li> <li><a href="contact">contact</a></li> 

the error isn't in code, rather fact you're including site javascript using relative paths:

when visit /testing/test javascript files return 404 because they're relative.

assets/js/main.js becomes /testing/test/assets/js/main.js

just use absolute paths or can setting base href

you should use developer console firebug or chrome dev tools watch errors. saw 404 errors , noticed js file.


Comments

Popular posts from this blog

html - Sizing a high-res image (~8MB) to display entirely in a small div (circular, diameter 100px) -

java - IntelliJ - No such instance method -

identifier - Is it possible for an html5 document to have two ids? -