Document Ready Function
You might have noticed, that all jQuery methods, in our examples, are inside a document.ready() function
// jQuery functions go here….
This is to prevent any jQuery code from running before the document is finished loading(is ready)
Here are some examples of actions that can fail if functions are run before the document is fully loaded :
- Trying to hide an element that doesn’t exist
- Trying to get the size of an image that is not loaded
How to use custom Scripts?
/* Filename : custom.js */
Now we can include custom.js file in our HTML file as follows :
<title> The JqueryExampe</title>
Click on this to see a dialogue box. </div>
Using Multiple Libraries
JQuery – noConfilct() Method
method to give control of the $ variable back to whichever library first implemented it. This helps to make sure that jQuery doesn’t conflict with the $ object of other libraries.
Definition and Usage
The noConflict() method releases jQuery’s control of the $ variable
This method can also be used to specify a new custom name for the JQuery variable
|removeAll||optional. A Boolean value that specifies whether or not release jQuery’s control of ALL JQuery variable (including “jQuery”)|
<h2>This is a heading </h2>
<p>This is a paragraph. </p>
<p>This is another paragraph </p>
Here is simple way of avoiding any conflict :
// Import other library
// Import jQuery
// code that uses jQuery’s $ can follow here.
// Code that uses other library’s $ can follow here.