Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use jQuery in HTML

In order to use jQuery, do I have to use the following reference in my html?

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

What if my server does not have an internet connection?

like image 512
george willy Avatar asked Feb 23 '12 14:02

george willy


People also ask

How can I use jQuery in HTML?

Step 1: Firstly, we have to open that Html file in which we want to add the jQuery using CDN. Step 2: After then, we have to place the cursor between the head tag just before the title tag. And, then we have to use the <script> tag, which specify the src attribute for adding.

Can we write jQuery in HTML?

You can write it directly to the HTML doc inside <script> tags or link with <script src="javascript. js"></script> .

Does jQuery go in HTML?

jQuery is a JavaScript file that you will link to in your HTML.

Why do we use jQuery in HTML?

The purpose of jQuery is to make it much easier to use JavaScript on your website. jQuery takes a lot of common tasks that require many lines of JavaScript code to accomplish, and wraps them into methods that you can call with a single line of code.


2 Answers

Use this code:

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript">window.jQuery || document.write('<script src="/res/jQuery/jquery-1.7.1.min.js"> \x3C/script>');</script>

This will try to download from the CDN, or otherwise use the local one. You must download the local one first though.

like image 140
Richard Avatar answered Sep 28 '22 06:09

Richard


It will not work if you don't have internet connection. To work locally you should copy jquery.js to your local directory and give relative path.

 <script src="/jquery/1.5/jquery.min.js"></script>
like image 21
Chuck Norris Avatar answered Sep 28 '22 07:09

Chuck Norris