I need lớn have a button & handle its sự kiện in jQuery.
Bạn đang xem: Onclick with button in material& I am writing this code but it"snot working. Did I miss something?
Bạn đang xem: Catch button click event jqueryWhy not just take it out of the enclosing btnClick function? I don't see what that adds – CodyBugstein Jul 23 "14 at 20:43
You have khổng lồ put the event handler in the $(document).ready() event:$(document).ready(function() ); }); $(document).ready(function()); // you can use the above or the one shown below $("your selector").click(function(e)); }); Good because is the onlyone who insert the preventDefault() – Gabrer Dec trăng tròn "14 at 11:16 As of jQuery 1.7, the .on() method is the preferred method for attaching sự kiện handlers to a document. Therefore this would be better: $('your selector').on("click", ...); – Tinynumbers Sep 2 "15 at 14:23 $("#btnSubmit").click(function());
or//Use this code if button is appended in the DOM $(document).on("click","#btnSubmit",function());
See documentation for more information: https://api.jquery.com/click/Button appended in the dom thing is always an issue if using notification like sweetalert.
Xem thêm: get year from datetime phpThanks for pointing it out – Deepesh Thapa Dec 27 "19 at 10:39 $(document).on("click", "#btnClick", function()); Click me This version has the benefit of still working if #btnClick is created after this script runs. – Jimbali Apr 27 "20 at 20:41 $("#btnSubmit").click(function(event));
or as you are using submit button so you can write your code in form"s validate sự kiện like$("#myForm").validate(function());
Works for me
Thanks for contributing an answer to Stack Overflow!Please be sure khổng lồ answer the question. Provide details và share your research!
But avoid …Asking for help, clarification, or responding to other answers.Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.Post Your Answer Discard