I’m working on a project, where I want to highlight the link (in a menu) that has the same href as another link on the site (in .container).
<ul class="menu">
<li><a href="about.html">Link 1</a></li>
<li><a href="portfolio.html">Link 2</a></li>
<li><a href="contact.html">Link 3</a></li>
</ul>
<div class="container">
<a href="contact.html">Go to Contact</a>
</div>
JS:
$("a").filter(function() {
return this.href === $('.container a').href;
}).addClass("equalHref");
Do you know how I can achieve this?
Your solution is very nearly correct:
or: