jQuery s on method combined with the submit event

0 votes

I've got a problem with .on(). I have multiple form-elements (forms with class="remember"), also I add another one form.remember using AJAX. So, I want it to handle submit event something like:

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

but form added with AJAX doesn't work with it.

Where is the problem? Is it a bug?

May 27, 2022 in JQuery by Edureka
• 13,690 points
763 views

1 answer to this question.

0 votes

You need to delegate event to the document level

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

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

answered May 30, 2022 by gaurav
• 23,260 points

Related Questions In JQuery

0 votes
1 answer

Error: cannot call methods on dialog prior to initialization; attempted to call method 'close'

Hello @kartik, Looks like your buttons are not ...READ MORE

answered Apr 28, 2020 in JQuery by Niroj
• 82,840 points
8,936 views
0 votes
1 answer

Error: cannot call methods on button prior to initialization; attempted to call method 'loading'

Hii @kartik, It's caused by jquery-ui and bootstrap-button ...READ MORE

answered May 12, 2020 in JQuery by Niroj
• 82,840 points
6,565 views
0 votes
1 answer

How to remove close button on the jQuery UI dialog?

Hii, I found this worked for me in the end ...READ MORE

answered May 12, 2020 in JQuery by Niroj
• 82,840 points
4,633 views
0 votes
1 answer

Error: cannot call methods on dialog prior to initialization; attempted to call method 'close'

Hello, Try this - it works for me: $(".editDialog").on("click", ...READ MORE

answered May 12, 2020 in JQuery by Niroj
• 82,840 points
1,349 views
0 votes
1 answer

JQuery Error: cannot call methods on dialog prior to initialization; attempted to call method 'close'

Hello @kartik, Try this - it works for ...READ MORE

answered May 29, 2020 in JQuery by Niroj
• 82,840 points
2,017 views
0 votes
1 answer

How can I determine the direction of a jQuery scroll event?

Hello @kartik, Check current scrollTop vs previous scrollTop var lastScrollTop = 0; $(window).scroll(function(event){ ...READ MORE

answered Nov 24, 2020 in JQuery by Niroj
• 82,840 points
870 views
0 votes
1 answer

jQuery Event : Detect changes to the html/text of a div

Hello, If you don't want use timer and ...READ MORE

answered Nov 25, 2020 in JQuery by Niroj
• 82,840 points
20,546 views
0 votes
1 answer

How to Get the real width and height of an image with JavaScript?

Hello, Webkit browsers set the height and width ...READ MORE

answered Nov 25, 2020 in JQuery by Niroj
• 82,840 points
692 views
0 votes
1 answer

What is the difference between AJAX with JavaScript and jQuery?

JavaScript is a programming language. JQuery is ...READ MORE

answered May 30, 2022 in JQuery by gaurav
• 23,260 points
796 views
0 votes
1 answer

Best cross-browser method to capture CTRL+S with JQuery?

$(window).keypress(function(event) { if ...READ MORE

answered May 30, 2022 in JQuery by gaurav
• 23,260 points
1,562 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP