Reputation: 23
I have a pagination, and my pagination is not using any plugin, I just create it by myself. But, I have a problem, how can I give a class='active'
when the button is clicked. I just using function in my pagination. Please help, thank you.
Upvotes: 0
Views: 622
Reputation: 310
$(document).on('click','your-element-class', function() {
if ($(this).hasClass('active')) {
$(this).removeClass('active');
} else {
$(this).addClass('active');
}
});
When the element is clicked, if it already has the active
class, it will be removed; otherwise it will be added.
Upvotes: 2