I'm trying to delegate a click
event to a link inside a table, as this jsFiddle sample shows :
The result you can see is:
- By clicking the " Enable " link, the
click
event assigned to the.activate
class is triggered, thereby changing the class of the same link to.deactivate
. - By clicking on the " Disable " link, the
click
event assigned to the.activate
class is fired again but nothing happens, and the correct execution of theclick
event is changed again its class to.activate
.
For a better understanding, please open the jsFiddle link.
Taking some examples that I had already done, and searching for cases similar to mine, I discovered that I should delegate the event as follows:
$(document).on("click", "#element", function (e) {});
However, I did not get the expected result, as you can see in this other jsFiddle sample . I am available to add more information if needed.