I have some nav links like so:
<ul id="nav">
<li><a href="index.html">Home</a>
<li><a href="about.html">About</a>
<li><a href="contact.html">Contact</a>
</ul>
How can I add a CSS class called active to the opening <li> tag of the list item that contains the a href whose value matches the current url?
For example, if the current page the user is on is about.html then the nav should look like this:
<ul id="nav">
<li><a href="index.html">Home</a>
<li class="active"><a href="about.html">About</a>
<li><a href="contact.html">Contact</a>
</ul>
Please note:
the urls can have additional parameters like:
about.html?foo=bar&bar=loo
so whatever is used to detect the url should not take parameters into consideration but just the page name and extensions.
I would prefer to achieve this in plain JavaScipt since I am not using jQuery for anything else on the site, but either is fine.
Edit
The index page had index.html in the url when it's landed on from another page but if the domain is types it shows as:
http://www.sitename.com/
so if no page is specified the active class should be attached to the home list's tag.