I want my JQuery to select one of the navigation links—based on the page that I'm on—and then I want it to move it to the top of the list.
This is the HTML of my navigation bar:
<nav>
<ul id=nav>
<li><a href="index.php">Home</a></li>
<li><a href="skillsets.php">Skillsets</a></li>
<li><a href="gallery.php"><icon>Gallery</a></li>
<li><a href="about.php">About</a></li>
<li><a href="contact.php">Contact</a></li>
</ul>
</nav>
This is the JQuery I'm using to try and reorder the list:
var page = document.location.pathname.match(/[^\/]+$/)[0];
var ul = $('nav').children('ul'),
li = ul.children('li');
$(document).ready(function(){
ul.prepend($('a[href*='+page+']').parent());
});
Needless to say, it isn't working.
By the way alert(page);
outputs the name of the file of the page that I'm on, ei: "contact.php", but alert($('a[href*=page]').parent());
just outputs "[object Object]"
. Any ideas? Thanks!