| | #1 |
| Active Warrior Join Date: 2012
Posts: 89
Thanks: 21
Thanked 5 Times in 5 Posts
|
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> 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. |
| |
| | #2 |
| Web Developer War Room Member Join Date: 2012 Location: Vancouver, BC
Posts: 593
Thanks: 149
Thanked 162 Times in 133 Posts
|
1. Don't use w3fools 2. That code above should work: Edit this Fiddle - jsFiddle |
| |
| |
| | #3 |
| Web Developer War Room Member Join Date: 2012 Location: Vancouver, BC
Posts: 593
Thanks: 149
Thanked 162 Times in 133 Posts
|
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> |
| |
| |
|
| Bookmarks |
| Tags |
| code, jquery, working |
| |