Assuming only one active element at a time and without further knowledge of your DOM hierarchy.
$('.active').removeClass('active'); $(this).addClass('active');
More efficient options are available if the DOM hierarchy is known.
For example, if they are all brothers and sisters, you can use this:
$(this).addClass('active').siblings('.active').removeClass('active');
source share