Register Advertise with usHelp Desk Today's Posts Search

Closed Thread
Thread Tools Search this Thread
Unread 22nd Jun 2013, 03:48 AM   #1
Active Warrior
 
Join Date: 2012
Posts: 89
Thanks: 21
Thanked 5 Times in 5 Posts
Default
jQuery code not working
Share on: 
fb share twitter share gplus share more share

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.
JoshuaReen is offline  
Unread 22nd Jun 2013, 10:26 AM   #2
Web Developer
War Room Member
 
Andrew H's Avatar
 
Join Date: 2012
Location: Vancouver, BC
Posts: 593
Thanks: 149
Thanked 162 Times in 133 Posts
Default
Re: jQuery code not working
Share on: 
fb share twitter share gplus share more share

1. Don't use w3fools
2. That code above should work: Edit this Fiddle - jsFiddle

"You shouldn't come here and set yourself up as the resident wizard of oz."
Andrew H is offline  
Unread 22nd Jun 2013, 10:29 AM   #3
Web Developer
War Room Member
 
Andrew H's Avatar
 
Join Date: 2012
Location: Vancouver, BC
Posts: 593
Thanks: 149
Thanked 162 Times in 133 Posts
Default
Re: jQuery code not working
Share on: 
fb share twitter share gplus share more share

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>

"You shouldn't come here and set yourself up as the resident wizard of oz."
Andrew H is offline  
Closed Thread


Bookmarks

Tags
code, jquery, working


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




All times are GMT -6. The time now is 12:24 PM.