Reputation: 9855
Im trying to say that, if my div doesnt have the class active add it. And if it does have the class active, remove it.
Ive the following, only my code adds the class, then continues the query and removes it at the end, what would the best solution be, 2 seperat click funcitons?
$('.work-showcase').click(function(){
if ( !$(this).hasClass('active') ){
$(this).addClass('active');
} else {
$(this).removeClass('active');
};
});
Upvotes: 2
Views: 124
Reputation: 647
$("#YourID").removeClass('ClassName'); $("#YourID").addClass('ClassName');
Upvotes: 0
Reputation: 145408
Use toggleClass
method:
$(".work-showcase").click(function() {
$(this).toggleClass("active");
})
Upvotes: 7