Reputation: 31
I have 3 checkboxes , I want to attach the click event on 2 but not the third . I am writing
<input type=checkbox />
<input type=checkbox />
<input type=checkbox id='selectAll' />
Script:
jQuery('input:checkbox:not(input#selectAll)').click(function(){
///my code comes here
});
The problem is click event is getting attached to all the checkboxes . I do not want the click event to get attached to the checkbox with id = selectAll.
Upvotes: 3
Views: 452
Reputation: 630339
The code you have works, you can test it here. Make sure some other event handler isn't getting attached that you don't want...or some other event isn't causing an event interaction with the "checkAll".
Also, be sure to always quote your attributes (like this)!, not doing so can have side-effects if there are any special characters/spaces, and it's just good practice anyway.
Upvotes: 3