3

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.

1 Answer 1

3

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.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.