I have a series of nodes I want to add a click handler to, the nodes will toggle an action, click once and something is set, click again and its cleared.
The problem is that the same handler is being installed more than once so a single click results in to calls to the handler.
How can I check if the handler is installed for the class and then only install if it isn't already installed?
I know there are similar posts to this already, however having read these I couldn't find one that solves my problem where I install then handler for the class.
[Edit], my code:
//Need to detect is handler has already been installed before adding the handler below:
$('.btnExpCol').click(function() {
//Do something when any element with this class is clicked
});
A lot of the comments are based around an 'id' which if you re-read my post, I am using a 'class' selector, however the issue has now been resolved and the solution works well.
[New code, which now works]:
$('.btnExpCol').off("click").on("click", function() {
//Do something when any element the has this class is clicked
});