I have few anchor tags inside a div and I need to retrieve the href values of all anchor tags. For example
<div id="sample">
<ul>
<li><a href="/location1">Location1</a></li>
<li><a href="/location2">Location2</a></li>
<li><a href="/location3">Location3</a></li>
<li><a href="/location4">Location4</a></li>
</ul>
</div>
Assuming I am in /location1
, the li
that has a href="/location1"
should have a separate background color, say for example red. If I am in /location2
the corresponding li
should have the same red color.
I am trying to retrieve the page url first and then store it in a variable.
var pageurl = (window.location.pathname);
But not too sure on how to retrieve the href and then map it based on the page urls.