Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why jQuery does not work on my home (local) machine?

Tags:

jquery

My question isn't so much about why a specific bit of jQuery I've written isn't working as it is about no jQuery at all is working; not even working examples I've copied directly from places like W3 Schools.

I use jQuery from time to time in my software development job and while I am by no means an expert, I am pretty familiar with it. For the first time I am trying to use jQuery in a home project and no matter what I do, none of it will work. The example I've included below is about as simple as I can think of, and even it will not work.

<!DOCTYPE HTML>
<html>
<head>
    <script src="//ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min.js"></script>
</head>
<body>
<div>
    <p>Old Stuff</p>
</div>
<script type="text/javascript">
   $('p').text('New Stuff');
</script>
</body>
</html>

What could possibly be wrong with this?

like image 753
jtrohde Avatar asked May 12 '13 16:05

jtrohde


People also ask

Does jQuery work locally?

Projects In JavaScript & JQueryYou can add jQuery using CDN or through downloading it on local machine. For Local Installation, download jQuery library on your local machine and include it in your HTML code.

Why jQuery is not working in server?

When jQuery scripts fail to work on your Web server, chances are the jQuery file is missing or you did not include it correctly in your HTML code. Your Web server itself will never cause jQuery to not work, because jQuery runs on your visitors' computers.

Why my jQuery is not working in HTML?

Be sure to import the jQuery library before your custom script is loaded. You will need to go the jQuery CDN and suss out a recent version 1 minified CDN URL. Go to the page “View all versions” (or something like that) and copy the link address of the minified version for 1.9. 3 or 1.10.

Do you need a server to run jQuery?

jQuery runs on the client side so simple answer is no.


2 Answers

The code is ok.

The script is not downloading because, as you probably are not deploying the code, the browser will default to the file:// protocol.

To solve it, add the http: at the script tag:

<script src="http://ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min.js">
                                                                           </script>
like image 141
acdcjunior Avatar answered Sep 28 '22 10:09

acdcjunior


change this

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

to this

<script src="http://ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min.js"></script>
like image 27
Emre Akay Avatar answered Sep 28 '22 10:09

Emre Akay