JQuery $ (document). Ready ()

Source: Internet
Author: User

Table of Contents
    • JQuery Document Ready Example
    • Multiple Document Ready Listeners

Whenever you use a jQuery to manipulate your Web page, you wait for until the document ready event has fired. The document ready event signals that the DOM of the page are now ready, so can manipulate it without worrying that par TS of the DOM have not yet been created. The document ready event fires before all images etc. is loaded and after the whole DOM itself was ready.

JQuery Document Ready Example

Here are a jQuery document Ready Listener Example:

$ (document). Ready (function () {    //dom Manipulation code});

You call JQuery's $ function, passing to it the document object. The $ function returns an enhanced version of the document object. This enhanced object has a ready() function of you can call and to which you pass a JavaScript function. Once the DOM is ready and the JavaScript function is executed.

Inside the function passed ready() to the method, you can execute all the JQuery and JavaScript code of need, in order to I Nitialize/enhance the HTML elements in your page. You'll see many examples of this, in the following pages.

Multiple Document Ready Listeners

JQuery allows you-register multiple document ready listeners. Just call $(document).ready() multiple times. Here are a multiple document ready listener example:

$ (document). Ready (function () {    //dom Manipulation code}), $ (document). Ready (function () {    //dom manipulation Code});

The listener functions registered in this example would both get called when the DOM was ready. They'll get called in the order they were registered.

Registering multiple document Ready event listeners can is really useful if you include HTML pages inside other HTML pages (e.g. using server side include features of your Backend/web server). Need some page initialization to occur both in the outer and inner page. Thus both the outer and inner page can register a document ready listener, and perform the page initialization they both n Eed.

JQuery $ (document). Ready ()

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.