OpenJS Foundation - openjsf.org · api.jquery.com

jQuery.readyReturns: Thenable

Description: A Promise-like object (or "thenable") that resolves when the document is ready.

  • version added: 1.8jQuery.ready

As of jQuery 3.0, use of this object is supported via jQuery.when or the native Promise.resolve(). Code should not make assumptions about whether this object is a jQuery.Deferred, native Promise, or some other type of promise object.

See also ready(), which makes use of this.

Examples:

Example 1

Listen for document ready using jQuery.when.

1

2

3

$.when( $.ready ).then(function() {

// Document is ready.

});

Example 2

Typical usage involving another promise, using jQuery.when.

1

2

3

4

5

6

7

$.when(

$.getJSON( "ajax/test.json" ),

$.ready

).done(function( data ) {

// Document is ready.

// Value of test.json is passed as `data`.

});

Read the original on api.jquery.com ↗