Reputation: 67
Im having a smallish issue with some tabs, Im trying to change the icon to a minus icon when on it and a plus icon when not on it if thats make sense.
Ive got it to change to a minus button when you click it but it wont change back when you click on another tab.
$('ul.nav-tabs li').click(function(){
$(this).find('i.tabIcon').removeClass('fa-plus').addClass('fa-minus');
$('ul.nav-tabs li:not(active)').removeClass('fa-plus').addClass('fa-minus');
});
any help would be greatly appreciated.
Upvotes: 1
Views: 502
Reputation: 14862
One approach is to remove the minus symbol on all icons, replacing them with the +
symbol, then add the minus symbol to only the icon of the li
that has been clicked on:
//Store as variable outside the function so we don't have to keep looking them up each
// time any of the li is clicked.
var $tabIcons = $('ul.nav-tabs li i.tabIcon');
$('ul.nav-tabs li').click(function(){
//remove - from all icons, add +.
$tabIcons.removeClass('fa-minus').addClass('fa-plus');
//remove + from this tab icon, add -.
$(this).find('i.tabIcon').removeClass('fa-plus').addClass('fa-minus');
});
Upvotes: 2
Reputation: 579
var selector = '.nav li';
$(selector).on('click', function(){
$(selector).removeClass('active');
$(this).addClass('active');
});
Upvotes: 0