I've been stumped by this all day. My page design needs to add a class to the 'a' tag of the active page, which creates a tab to let the user know that is the page they are currently on. I have been able to apply the class when I use e.preventDefault(), but this stops the link from going to the assigned href.
When I don't use the e.preventDefault(), the class does get assigned, but only for half a second before the new page loads and it defaults back to it's original HTML. The code is as follows:
$(document).ready(function () {
$(".navigation a").click(function (e) {
$(".navigation a").removeClass("act");
$(this).addClass("act");
});
})
And here is the HTML:
<div class="navigation">
<a class="nav_item class1" href="/url/">link text</a>
</div><!-- navigation -->
<div class="navigation">
<a class="nav_item class2" href="/url/">link text</a>
</div><!-- navigation -->
<div class="navigation">
<a class="nav_item class3" href="/url/">link text</a>
</div><!-- navigation -->
Any help would be appreciated. Thanks!