Skip to content Skip to sidebar Skip to footer

Why Is Click Event Attached To Classname Fired After Classname Is Removed?

Related: Jquery timeout for doubleclick Given this code: the fire className is removed from .onlyfire element following 2000ms, where expected result is for click event which was

Solution 1:

That is expected behaviour.

Once an event handler is attached, the class changes made to that element do not influence the fact that the event will trigger the event handler. The class only plays a role in finding the element to attach the handler to. Once that is done, the class selector plays no role any more.

Solution 2:

Event handlers are bound to elements not to their classNames. Static event handlers do not work like delegated event handlers.

Post a Comment for "Why Is Click Event Attached To Classname Fired After Classname Is Removed?"