0

I'm using AJAX to request a sub section of my page. Here is an example of what the content requested could look like:

<div id="NewContentAfterPageLoad">
   <form>
     ...
     <input id="clickMe" type="submit" form="aForm" value="submit">
   </form>
</div>

<script>
   $(document).ready(function(){ 
      $('#clickMe').on('click', '#clickMe', function(e) {
         alert();
      });
   });
</script>

So this content is not present on page load.

Adding the jQuery like this doesn't work even though I'm using delegates.

Does this mean that any jQuery has to be present on page load for the browser to read it?

Is there a workaround for dynamically loaded jQuery?

Juicy
  • 11,840
  • 35
  • 123
  • 212

1 Answers1

1

You need to attach event to element that does not change dynamically. you can also use them with $('body') or $(document).:

  $('body').on('click', '#clickMe', function(e) {
     alert('test');
  });
Milind Anantwar
  • 81,290
  • 25
  • 94
  • 125