jQuery click event still firing on filtered element
Posted
by Phil.Wheeler
on Stack Overflow
See other posts from Stack Overflow
or by Phil.Wheeler
Published on 2010-05-21T01:44:52Z
Indexed on
2010/05/21
1:50 UTC
Read the original article
Hit count: 266
I'm trying to filter button events based on whether they have a CSS class assigned to them or not.
Assume I have a button like this:
<button id="save-button" class="ui-state-default ui-corner-all">Save</button>
I want to get jQuery to select all buttons that currently do not have a class of "ui-state-disabled". The selector I'm using looks like this:
$('#save-button:not(.ui-state-disabled)').click(function() {
...
});
When the button is clicked, I'll call a different function, do some stuff and then add the class 'ui-state-disabled' to the button. However the button still continues to accept click events.
I'm guessing this is because of two possible causes:
- The event binder looks only at the initial state when binding the click event and doesn't recognise that a new class has been added later on
- My filter ['... :not(.ui-state-disabled)] is not correct
Any observations?
© Stack Overflow or respective owner