I think i should use the window.location.pathname to get the url. and store in a var called page_name
then i want to say, if the windows.location.pathname is in the url bar, then add active class to my
here is what i have so far. let me know what i need to change.
<div class="nav-collapse">
<ul id="nav" class="nav">
<li id="home"><a href="home_page.php">Home</a></li>
<li id="watch"><a href="watch.php">Watch</a></li>
</ul>
</div>
$(document).ready(function(){
var page_name = window.location.pathname.substring(1);
$('li[href$="' + page_name + '"]').addClass('active');
});
If you ask why your script doesn’t work, then I assume that your jquery selector is wrong. Try this:
nav.js:
common.css:
{home_page, watch}.html: