JQuery.click not working

We have a problem in IE with some users where the onclick event does not work:

<button type="button" id="btnSomething" name="btnSomething" onClick="myFunction();">Continue</button>

After digging on the net, people suggested using jQuery.click for browser compatibility.

So, I tried the following:

<script type="text/javascript">$('#btnSomething').click(function(){myFunction();});</script>

This does not work, I tried adding to alert ('test'); but it is also not caused. If that matters, I did not delete onClick = "myFunction ();" from the button element, simply adding the above JS directly after the button in the HTML file.

+3
source share
5 answers

. -, DOM. jQuery : jQuery document.ready:

$(document).ready(function(){
    $('#btnSomething').click(function(){
        around ();
    });
});

-, (around), ; :

$(document).ready(function(){
    $('#btnSomething').click(around);
});
+2

, document.ready, , :

<script type="text/javascript">
  $(function(){ 
    $('#btnSomething').click(around);
  });
</script>

ready, $('#btnSomething') , DOM.

+1

, , false , .

0

,

jquery lib, - :

<script src= "http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js" type="text/javascript"></script>

$(function(){
   $('#btnSomething').click(function(){
       around ();
   });
});

onclick - javascript. , .

0
source

It works great. be sure to run jQuery code in the domready block. see here: http://jsbin.com/inubo4

0
source

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


All Articles