How to connect jQuery?
Watch the video
Modern services like YouTube would not workwithout JavaScript, which interacts with HTML. That's why the jquery program library was developed, with the help of which this interaction takes place. However, few Internet users know what jquery is and how to connect and use it.
Let us consider this issue in more detail below.
How to install jQuery
Nothing complicated in how to connect the libraryjquery, no. However, there are several simple differences when connecting a library in different ways. After all, there are several ways, depending on the situation:
- Connecting jquery from the page of your site.
- Connecting jquery through Google.
- Dynamic jquery connection.
Let's consider each case separately.
Connecting jquery from the page of your site
This method is suitable if the site is self-described, withoutmanagement systems like WordPress. If your site meets these requirements and you want to download the library directly from it, you need to perform a number of simple actions:
- Download the fresh jquery assembly from the developer's site. Experienced webmasters advise the "PRODUCTION" version so that your site loads the library faster.
- Upload the library file to the site.
- We write the code "<script type =" text / javascript "src =" file address "> </ script>" inside the Head tag.
After that, the library will work.
How to install jquery through Google
Google has a special Google serviceLibraries API, which allows you to connect the library through their service. This is convenient because the library will load much faster than from your site, and will be present in the cache of most browsers.
To connect the library in this way, it is enough to write the code the same way as in the previous paragraph of the article:
- <script type = "text / javascript" src = "Google service address"> </ script>
And to find out the address of the service at the moment, you need to go to the Google Developers site and see it.
Dynamic jquery connection
Dynamic connectivity means that the librarywill be loaded not with the site, but after the user performs some specific action. In this case, the code will look like this:
- var script = document.createElement ("script");
- script.type = "text / javascript";
- script.src = 'Google service address';
- document.getElementsByTagName ("head") [0] .appendChild (script);
- script.addEventListener ("load", function () {
- $ (document) .ready (function () {
- alert ("jQuery is loaded.");
- });
- }, false);
Thus, the function of executing the command is given.
Also you can read our useful section Web Development.