How to insert jQuery into my own html?

How to insert jQuery into my own html?
0

#1

Lately I’ve been trying to insert jQuery into my own private html, but it doesn’t seem to explain it here, so I found some other code that said to put this

<\script src=“https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js”>
I put the back-slash before the script cause it wouldn’t show unless I did.

But it doesn’t seem to make anything work better.


#2

Ok, so it sounds like you are really at the beginning of getting into Javascript, which means that jumping right into jQuery is maybe not the best track to be on.

Start here to get an idea of what Javascript is and how to use it in a page:
MDN Primer on Javascript Basics

Start here to begin learning about including the jQuery javascript library on your page and how to begin using it:
jQuery introduction by jQuery Foundation

I do not recommend getting into using jQuery before you have a good conceptual understanding of the basics of Javascript. jQuery is a javascript library - written in javascript. To understand it and use it well (it’s very easy to use it poorly), it’s a very good idea to have a basic grounding in the fundamentals of javascript itself.

Hope that helps!


#3

I’ve done a lot of JavaScript, I’m only just barely learning how to use jQuery. I just want to know how to insert the jQuery library.


#4

probably

should be <script src=“https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js”></script> at least that is what I use


#5

It’s the same as any other external javascript file - you should put a <script>

tag at the bottom of the body. with the src set to the location of the jquery library you want to use.

From there, you will insert your own script block below that one where you will put your custom code. You usually want to wait until the document ready event has been fired to execute your code to make sure that the document is fully loaded and ready to go.

Something like:


<script>
   $( document ).ready( function(){

      // YOUR CODE HERE

   });

</script>

#6

hum? http://www.w3schools.com/js/js_whereto.asp


#7

So if I inserted this

<script src="https://ajax.aspnetcdn.com/ajax/jQuery/jquery-3.1.1.min.js"> $(document).ready(function() { $("#example").css("background","red"); }); </script>

Then it would change #example’s background-color to red, right?


#8

Wrong, those are 2 different scripts, jQuery and your own and they should be declared separately (2 times). It will be something like
<script src=“https://ajax.aspnetcdn.com/ajax/jQuery/jquery-3.1.1.min.js”></script>

<script>
$(document).ready(function() {
$("#example").css(“background”,“red”);
});
</script>

hope I was clear enough :wink:
EDIT: dumb lt; char


#9

Oook, thanks that was very helpful.