I want to run a function when a checkbox is checked or unchecked. However, I have around 70 checkboxes. They are all within a div. How can I write one command that will react to any of them being changed?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Events bubble up, so you can just attach an onchange handler to the div and use
e.targetto get the checkbox that changed. Here’s a simple example of this:HTML:
Javascript:
And here’s a JSFiddle