Inside jQuery, I have the following:

JQuery.on () not working

I have the following:

<input type="submit" id="submit" value="Submit" /> 

Inside jQuery, I have the following:

 <script type="text/javascript"> $(document).ready(function () { $("#submit").on("click", function () { alert('test'); }); }); </script> 

This does not work. I am using IE9.

Can anyone find out which version of jQuery supports .on() ?

+6
source share
6 answers

Use this version on

 $(function(){ $(document).on("click","#submit", function (e) { //e.preventDefault(); // if you want to prevent default form submission alert('test'); }); }); 
+6
source

make sure you download jQuery.js , then try:

 $("#submit").click(function(){ alert("test"); }) 
+3
source

Try the following alternatives:

  $('#submit').bind('click', function() { alert('Test'); }); 

OR

 $("#submit").click(function(){ alert("Test"); }); 
+1
source

IE is not suitable for using "reserved" names as an identifier for an element.

Look at this fiddle, your code is great if you change the input id to something other than "#submit"

http://jsfiddle.net/6yAuz/3/

+1
source

Make sure that the submit element that you are referring to actually exists when the document is loaded. If you create it dynamically, the 'on' function will not be able to bind it to.

0
source

I came across this using IE9 in compatibility mode. Please note: I had no problems using IE9 in normal mode.

I was able to do a more thorough QA for the site I just launched (time did not allow a lot of cross-browser testing, except for using the screenshot service). Change $ ("something"). On ("click" ...) to $ ("something"). Click () fixed the problem.

0
source

Source: https://habr.com/ru/post/920254/


All Articles