JQuery does not work in Firefox

jQuery does not work in Firefox. It works fine in IE and Google chrome, but when I try to run my application in Mozilla Firefox, jQuery does not work. Any guesses? Here is my code snippet

<!DOCTYPE HTML PUBLIC> <html> <head> <script type="text/javascript" src="http://code.jquery.com/jquery-1.7.1.js"></script> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.16/jquery-ui.js"></script> <style> div{ width:200px; height:100px; border:1px solid red; } </style> </head> <body> <div> One</div> <div>Two</div> <div>Three</div> </body> <script> $('div').click(function(){ alert("Hello....."); }); </script> </html> 
+4
source share
3 answers

you must use the readiness event at home

 $(document).ready(function(){ $('div').click(function(){ alert("Hello....."); }); }); 
+9
source

Put the jquery code inside document.ready .

  $(document).ready(function() { $('div').click(function(){ alert("Hello....."); }); }); 

Give your div a suitable class. Just like

 <div class="clsDiv"> One</div> 

amd call it.

  $('.clsDiv').click(function(){ 
+3
source

lukenz and shree nailed him. JQUery event handlers for html elements must first be registered with $ (document) .ready ().

0
source

All Articles