jQuery code not working

2 replies
  • WEB DESIGN
  • |
I am learning jQuery to design a website. But I have some problem. I am learning from w3schools website. The code works well in w3schools try it editor, but does't work in my website. Here is the code.

Code:
<html>
<head>
<title>Learn jQuery</title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js">
$(document).ready(function(){
  $("p").click(function(){
    $(this).hide();
  });
});

</script>
</head>

<body>
<p>If you click on me, I will disappear.</p>
<p>Click me away!</p>
<p>Click me too!</p>
</body>
</html>
The paragraph should disappear when clicked, but actually it doesn't work. I have put it in a PHP page. Here is the link to page where I am testing my jQuery codes.
Learn jQuery
Just check the page and you will see that the paragraph doesn't disappear when clicked. Please help me to solve this problem.
#code #jquery #working
  • Profile picture of the author Andrew H
    1. Don't use w3fools
    2. That code above should work: Edit this Fiddle - jsFiddle
    Signature
    "You shouldn't come here and set yourself up as the resident wizard of oz."
    {{ DiscussionBoard.errors[8200610].message }}
  • Profile picture of the author Andrew H
    Ohh simple mistake, you need to close the first script tag that is loading jquery library and open a new tag for your JS.

    Code:
    <html>
      <head>
      <title>Learn jQuery</title>
      <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"></script>
      <script type="text/javascript">
         $(document).ready(function(){
            $("p").click(function(){
                $(this).hide();
             });
        });
    
       </script>
       </head>
    
       <body>
          <p>If you click on me, I will disappear.</p>
          <p>Click me away!</p>
          <p>Click me too!</p>
        </body>
      </html>
    Signature
    "You shouldn't come here and set yourself up as the resident wizard of oz."
    {{ DiscussionBoard.errors[8200616].message }}

Trending Topics