jQuery event target repitition
I have simple a function that will look for a specific class
('.clickable') and add a class when it's clicked ('.last-clicked). I want
to remove the ('.last-clicked') class from all other existing elements so
there is only one item with that class.
$('.clickable').click(function(event) {
$('.clickable').removeClass('last-clicked');
$(event.target).addClass('last-clicked');
});
My function works but it seems silly to refer to $('.clickable') in the
wrapper and the function. Is there a more efficient approach?
No comments:
Post a Comment