I have 5 button each of them have the class .leg, I want when the user clicks on one of them to add 'active' on the class attribute and remove it from every other, so I have:
j$(".leg").on "click", (event)->
j$('.leg').removeClass('active')
j$(event.target).addClass('active')
Sometimes when I click on one of the button the 'active' class is not added. I suspect that the removeClass has not finish its execution, 'active' is added and then removed again. Since the removeClass
does not have a callback is there any other way to fix this issue?
Use
$(this)
instead of$(e.target)
:this
is the dom element selected when you added the click handler.JSFIDDLE