Let's say I have something like this:
$('#mydiv').on('click', 'button', doSomething);
Obviously I want all buttons to doSomething()
on click. Now let's say I want one of those buttons to NOT do that, but do something else.
$('#mydiv').off('click', '.specialclass button');
This does not work, but I need it to. Is there a way to achieve this? I'd very much prefer not to have to wire up each button individually.
This part of the .off()
documentation is what's killing me:
To remove specific delegated event handlers, provide a selector argument. The selector string must exactly match the one passed to .on() when the event handler was attached.
Here's a fiddle demoing what I'm trying to do.