| Start |
|---|
| Getting Started Create a file Live Demo on JSBin (opens new window) Open this file in a web browser. As a result you will see a page with the text: Explanation of codeThis introduces the
For more refer to the jQuery - Documentation (opens new window) page. |
| Avoiding namespace collisions Libraries other than jQuery may also use To release After calling this function, Optionally, you can assign a different variable as an alias for jQuery: Conversely, to prevent other libraries from interfering with jQuery, you can wrap your jQuery code in an immediately invoked function expression (IIFE) (opens new window) and pass in Inside this IIFE, Another simple way to secure jQuery's To summarize,
Now, there exists a third scenario - What if we want jQuery to be available only in
This results in neither This is useful when multiple versions of jQuery are to be loaded onto the same page. https://learn.jquery.com/using-jquery-core/avoid-conflicts-other-libraries/ (opens new window) |
| jQuery Namespace ("jQuery" and "$")
Assuming we have this snippet of HTML - We might want to use jQuery to add some text content to this div. To do this we could use the jQuery Or - Both will result in the same final HTML - As jQuery uses CSS selectors and in the example above an ID selector was used. For more information on selectors in jQuery see types of selectors (opens new window). |
| Loading jQuery via console on a page that does not have it. Sometimes one has to work with pages that are not using In such situations one can use Version you want might differ from above( |
| Include script tag in head of HTML page To load jQuery from the official CDN (opens new window), go to the jQuery website (opens new window). You'll see a list of different versions and formats available. Now, copy the source of the version of jQuery, you want to load. Suppose, you want to load jQuery 2.X, click uncompressed or minified tag which will show you something like this: Copy the full code (or click on the copy icon) and paste it in the The best practice is to load any external JavaScript libraries at the head tag with the When using |
| The jQuery Object Every time jQuery is called, by using Internally jQuery refers to its prototype as In addition to setting up an instance (which is how the jQuery API, such as A simple demonstration would be to find an element with an id, and then access the jQuery object to return the underlying DOM element (this will also work when multiple elements are matched or present). |
| Loading namespaced jQuery plugins Typically when loading plugins, make sure to always include the plugin after jQuery. If you must use more than one version of jQuery, then make sure to load the plugin(s) after the required version of jQuery followed by code to set Now when initializing the plugins, you'll need to use the associated jQuery version It is possible to only use one document ready function to initialize both plugins, but to avoid confusion and problems with any extra jQuery code inside the document ready function, it would be better to keep the references separate. RemarksjQuery is a JavaScript library which simplifies DOM operations, event handling, AJAX, and animations. It also takes care of many browser compatibility issues in underlying DOM and javascript engines. Each version of jQuery can be downloaded from https://code.jquery.com/jquery/ (opens new window) in both compressed (minified) and uncompressed formats. |
Read Article
https://develop.horje.com/learn/1434/reference