0

This question has been asked but this one is a little more specific, the others didn't give me an answer, thou they helped.

I have some html code like so, it's this way AFTER the j query executes:

<td><div class="switch has-switch"><div class="switch-animate switch-off"><input type="checkbox" data-toggle="switch" data-shopify="10700" data-order="90312" class="ct-primary printing" value="0"><span class="switch-left">DONE</span><label>&nbsp;</label><span class="switch-right">NOT</span></div></div></td>

The above html is just a check box that I can check or uncheck. Using the following Jquery code the above gets the div added to it:

  $(function () {
    $('.switch').each(function () {
      $(this).bootstrapSwitch();
    });

    $('[data-toggle="switch"]').each(function () {
      $(this).wrap('<div class="switch" />').parent().bootstrapSwitch();
    });
  });
}(jQuery);

My challenge is when I pull data from Ajax it no longer works since the J query has already loaded. I've read to use "on" but I'm not sure where I would add that into this current J query code. How can I change this code to work on new elements provided by an Ajax call?

FabricioG
  • 3,107
  • 6
  • 35
  • 74

0 Answers0