I have a pure HTML/CSS navigation bar in 4 pages, like this:
<nav id="bar">
<ul id="nav">
<li><a href="aa.html">AA</a></li>
<li><a href="bb.html">BB</a></li>
<li id="page">CC</li>
<li><a href="dd.html">DD</a></li>
</ul>
</nav>
I can get the page name using javascript, with
var pagename = window.location.pathname.split('/').pop();
I want to use Jquery to add the same code to every page, and, depending on the html page, remove the a link and change the id using something like (pseudocode):
$("#nav").append(<li><a href="aa.html">AA</a></li>
<li><a href="bb.html">BB</a></li><li><a href="cc.html">CC</a></li><li><a href="dd.html">DD</a></li>
$("#nav").find(pagename).parent().removelink_and_add_the_"page"_id()
That is, if the current page is DD.html, the navigation bar changes the <li><a href="dd.html">DD</a></li>
to <li id="page">DD</li>
Is it posible? Any hint?
Thank you in advance!!
2
Answers
Find the
<a>
using css attribute selectors:Then change the id of the parent, add the DD text to the parent, and finally use
.remove()
on myElem