Reputation: 827
I keep having this issue with many different code snippets in JQuery where the code I try works on sites like JSFiddle and w3schools, but doesn't work on my computer when I just try to load an html file through Chrome.
My question is, to run JQuery locally, do you need compiling software like you would need with C, or should it work like HTML/CSS does with just a browser?
Here's an example of some simple code that works in JSFiddle and w3schools but doesn't work for me...
<!DOCTYPE html>
<html>
<head>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js">
</script>
<script>
$(document).ready(function(){
$("button").click(function(){
$("p").hide();
});
});
</script>
</head>
<body>
<h2>This is a heading</h2>
<p>This is a paragraph.</p>
<p>This is another paragraph.</p>
<button>Click me</button>
</body>
</html>
Additionally, if a compiler is required. Can you recommend one to me? Thanks for all your help!
Upvotes: 2
Views: 2762
Reputation: 55623
Ok, using the // syntax doesn't work when you're running through the local file system - it looks for file://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js
Obviously that file doesn't exist and jQuery isn't loaded on the page. You need to specify it as an HTTP(s) resource if you're going to open it locally:
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js">
</script>
Upvotes: 8
Reputation: 44740
You need to use http:
like this -
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js">
Upvotes: 4