Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jquery checkbox

Tags:

jquery

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.

like image 724
user556886 Avatar asked Feb 16 '26 13:02

user556886


1 Answers

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.

like image 68
Nick Craver Avatar answered Feb 18 '26 16:02

Nick Craver



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!