Reputation: 9247
How can i change class .active-link when i click on other anchors?
<div id="settings" class="account-collapse collapse in">
<div class="account-body">
<a href="#/PersonalInfo" class="active-link">PERSONAL_INFORMATION</a>
<a href="#/Notifications">NOTIFICATIONS_SETTINGS</a>
<a href="#/PasswordChange">CHANGE_PASSWORD</a>
<a href="#">GAME_SETTINGS</a>
</div>
</div>
I tried this but its not working:
$('div').click(function () {
var hash = window.location.hash;
$("a.active-link").removeClass();
$('a[href="' + hash + '"]').addClass('active-link');
});
Upvotes: 0
Views: 155
Reputation: 15393
Try
$('#settings a').click(function(event) {
event.preventDefault(); // prevent default action
$('#settings a').removeClass('active-link'); // remove all active class
$(this).addClass('active-link'); // apply for current a tag
});
Upvotes: 2
Reputation: 8291
$('#settings a').not('.active-link').click(function(){//when other links are clicked
$('#settings .active-link').removeClass('active-link').addClass('mynewclass');
})
DEMO: https://jsfiddle.net/fuk4cyk4/2/
Upvotes: 0