How to connect jQuery?

How to connect jQuery?

Watch the video

How to connect jQuery?

modern services like YouTube would not work without JavaScript, which, cooperating with HTML.That's why software library jquery, through which this interaction occurs and has been developed.However, very few Internet users know what a jquery and how to connect and use it.

Consider this question in more detail below.

How to install jQuery

Nothing complicated about how to connect jquery library, no.However, there are some simple differences when connecting the library in different ways.After all, these methods depending on the situation somewhat:

  • jquery connection with your site.
  • Connecting jquery through Google.
  • Dynamic connection jquery.

consider each case separately.

connection with jquery pages of your site

This method is suitable if the site samopisny without management systems like WordPress.If your site meets these requirements and you want to boot directly to the library with him, it is necessary to perform a number of simple steps:

  1. Load latest jquery assembly from the developer.Experienced webmasters are advised to version «PRODUCTION», so that your site was loading the library quickly.
  2. downloaded on the site of the library file.
  3. code prescribes «& lt;script type = "text / javascript" src = "file address" & gt; & lt; / script & gt; »inside the Head tag.

After this library will work.

How to install jquery through Google

company Google has a special service Google Libraries API, which allows you to connect through their library service.It is convenient that the library will load much faster than with your site, and will be present in the cache of most browsers.

To connect this way the library is enough to register in the same way as in the previous paragraph of Article code:

  • & lt;script type = "text / javascript" src = "address of the Google service" & gt; & lt; / script & gt;

And to find out the address of the service at the moment, you need to go on the Google Developers website and see it.

Dynamic connection jquery

dynamic connection means that the library will be loaded not with the site, and after the user performs some specific action.In this case, the code would look like this:

  • var script = document.createElement ( 'script');
  • script.type = 'text / javascript';
  • script.src = 'service address Google';
  • document.getElementsByTagName ( 'head') [0.appendChild (script);
  • script.addEventListener ( 'load', function () {
  • $ (document ready (function () {
  • alert ( 'jQuery loaded.');.
  • });
  • }, false);

Thusis given by the function of the command.

you can also read our helpful section Web development.