0

I have a multiple checkboxs loaded from another file by ajax with class 'chk-bx'

<script>

$('.chk-bx').on( "click", function(){

   alert("checked");
   });

</script> 

There are some checkboxes that are there beore loading ajax then its working fine. but after loading its not working.

Thanks you verymuch

kodak
  • 13
  • 3

1 Answers1

0

The event handler is initialized before the checkboxes get to the DOM. You have to initialize the handler on the new checkboxes after they appeared in the DOM.

Edit: As Rory said, you can use a delegated event handler. You can attach the handler to a common parent of your checkboxes, like $( "#checkbox-container" ).on( "click", ".chk-bx", function() {...}). That way the newly added checkboxes in the #checkbox-container element will have that listener ran on a click event. You can read more about it here: https://learn.jquery.com/events/event-delegation/

bgazsi
  • 141
  • 8