JQuery.on () send event

I have a problem with .on() . I have several form elements (forms with class="remember" ), I also add another form.remember using AJAX. So, I want it to handle the send event, for example:

 $('form.remember').on('submit',function(){...}) 

but the form added in AJAX does not work.

Where is the problem? This is mistake?

+52
jquery ajax submit forms
Aug 31 '13 at 8:01
source share
2 answers

You need to delegate the event to the document level.

 $(document).on('submit','form.remember',function(){ // code }); 

$('form.remember').on('submit' works the same as $('form.remember').submit( but when you use $(document).on('submit','form.remember' , then it will also work for the DOM added later.

+124
Aug 31 '13 at 8:06
source share

I had a problem with the same symmetries. In my case, it turned out that my return function is missing a return statement.

For example:

  $("#id_form").on("submit", function(){ //Code: Action (like ajax...) return false; }) 
+10
Mar 29 '16 at 17:17
source share



All Articles