Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery is not working in Firefox

jQuery is not working in Firefox. It works fine in IE and Google chrome, but when I am trying to run my application in Mozilla Firefox jQuery is not working. Any guesses? Here is my piece of code

<!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>
like image 213
Rama Rao M Avatar asked Dec 16 '22 20:12

Rama Rao M


2 Answers

you should use the dom ready event

$(document).ready(function(){
  $('div').click(function(){
   alert("Hello.....");
  });
});
like image 136
lukenz Avatar answered Jan 02 '23 01:01

lukenz


Put your jquery Code inside document.ready.

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

 });

Give your div a proper class.just like

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

amd call like this.

 $('.clsDiv').click(function(){
like image 37
4b0 Avatar answered Jan 02 '23 02:01

4b0