How do I disable a link in jQuery? Previously I was changing the anchor's href attribute but realized this would not be the best way to stop the user being taken to a new page. I added disabled true to the attribute instead but this isn't working. The click still needs to work - I just don't want the link in the anchor to activate.
var acc = document.getElementsByClassName("dropdown-nav");
var i;
for (i = 0; i < acc.length; i++) {
acc[i].addEventListener("click", function() {
this.classList.toggle("active-hit");
this.find('a').attr('disabled', true);
//this.find("a").attr("href", "#");
});
}
<ul>
<li class="dropdown-nav">
<a href="/about">About
<span class="nav-desc">Our company</span>
</a>
<div class="hide-border"></div>
<ul class="second-tier">
<div class="hide-corner"></div>
<li><a href="#">Our Mission</a></li>
<li><a href="#">Our People</a></li>
<li><a href="#">Work with us</a></li>
<li><a href="#">High Value Manufacturing</a></li>
</ul>
</li>
</ul>