romaer
romaer

Reputation: 49

simple jQuery script not running

I just have copied a simple script from W3School and cannot get it running: Here it is:

<!DOCTYPE html>
<html>
<head>
<script type="text/javascript" src="http://Web Testing/js/jquery-1.8.0.min.js">
</script>
<script>
$(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>

It works on their Tryit Editor with the following line but does not work even with this line on my Mac under BBEdit

Upvotes: 3

Views: 1908

Answers (4)

NullPoiиteя
NullPoiиteя

Reputation: 57322

you ned to include jquery the link you included is not working

try

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>

also useing the google hosted libraries is a good option because many other website using it so in most case it will get in browser cache

Upvotes: 6

Akash Shende
Akash Shende

Reputation: 599

<script src="http://code.jquery.com/jquery-1.8.3.min.js" type="text/javascript">
   <!--left blank-->
</script>



<script type="text/javascript">

  $(document).ready(function(){

       /*Your code*/

     });

</script>

Upvotes: 2

Winter Bash
Winter Bash

Reputation: 403

you need to include jquery before use . or if you include jquery after script than use ready or load event

tp include jquery you can either choose google hosted library or jquery

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>

or

<script type="text/javascript" src="http://code.jquery.com/jquery-1.8.3.min.js"></script>

Upvotes: 1

user2742371
user2742371

Reputation:

<script type="text/javascript" src="http://Web Testing/js/jquery-1.8.0.min.js"></script>

The link to the jquery library is invalid, replace that code with this:

<script type="text/javascript" src="http://code.jquery.com/jquery-1.8.3.min.js"></script>

Upvotes: 1

Related Questions