0

I'v been reading other answers about dynamically generated elements and event listeners but I still don't get how to do it with my case:

I appended a few check boxes to a list with:

$('#divId').append(...)

So the result is something like this:

<div id="divId">
    <label><input type="checkbox" id="0"...> Element 0 </label>
    <label><input type="checkbox" id="1"...> Element 1 </label>
.
.
.
</div>

Every element have a different id but i don't know how to add an event listener that listens to all the elements on that list. Something like:

$([ALL THE CHECK BOXES IDS]).change( function() {
    if( $(this).is(":checked)"){
        // do stuffs...
    } 
});
F. Retamal
  • 23
  • 6
  • In case it's not perfectly clearhow to apply the duplicate to your situation, the solution is `$("#divId").on("change", "input[type='checkbox']", function() { ... })`. to run a listener for any and all checkboxes inside `divId` for all time (not merely the checkboxes that exist at the time you run the `.on` call) – apsillers Oct 23 '17 at 16:07
  • @apsillers thank you, this is what I was looking for – F. Retamal Oct 23 '17 at 17:34

0 Answers0