javascript - Append #hashtag to link in HTML on the fly -
i have nav, each link in nav appends hashtag on existing url when clicked, live filtering, etc. use of jquery.
i want append same current hashtag series of links within div further down page.
for example, i've clicked "work" , url looks like:
http://www.domain.com/page.html#work
i have series of links in page:
<div id="links"> <ul> <li><a href="http://www.domain.com/link1">link1</a></li> <li><a href="http://www.domain.com/link2">link2</a></li> <li><a href="http://www.domain.com/link3">link3</a></li> <li><a href="http://www.domain.com/link4">link4</a></li> </ul> </div>
these links within div#links need updated on fly append #work on url's when clicked hashtag appended.
is possible? make sense?
you should attach click
event handler links in #nav
, change links in #links
accordingly. [see in action]
javascript
$("#nav a").click(function() { $("#links a").each(function() { this.href = this.href.split("#")[0] + "#" + window.location.hash; }); });
html
<div id="nav"> <a href="#work">work</a> - <a href="#school">school</a> </div>
Comments
Post a Comment