vaxxis
vaxxis

Reputation: 253

Checkbox onClick issue with jquery

i have an issue with checkboxes and jquery. I set and event click on father(div) that check the checkbox, but if i click on checkbox directly it dosen't check.

You can find the code here: http://jsfiddle.net/vaxxis/65MBb/

Thanks.

Upvotes: 0

Views: 213

Answers (3)

voigtan
voigtan

Reputation: 9031

you can look what element was clicked, if its the input, don't run the script, else run it: http://jsfiddle.net/65MBb/14/

Upvotes: 0

Serg Hospodarets
Serg Hospodarets

Reputation: 4678

How about that: http://jsfiddle.net/65MBb/8/ ?
All that is necessary - wrap inputs in label. Then do not need JavaScipt.

Upvotes: 3

Jules
Jules

Reputation: 7213

This happens because when you click the checkbox the event $('.ckb').click() is also fired. So it does get checked, but gets immediately unchecked again right afterwards because of your function.

So in your click() function you have to make sure that it was the div that was clicked and not the checkbox.

Upvotes: 0

Related Questions