George Mauer
George Mauer

Reputation: 122172

Is jQuery.ready useful on anything other than document?

I was thinking about the jQuery $(document).ready event and it occurs to me that I've never seen anyone apply it on anything other than $(document). Is there any other legitimate use for it?

Upvotes: 7

Views: 118

Answers (3)

Eliasdx
Eliasdx

Reputation: 2180

From the jQuery documentation:

The .ready() method can only be called on a jQuery object matching the current document, so the selector can be omitted.

They all do the same:

$(document).ready(handler)
$().ready(handler) (this is not recommended)
$(handler)

Source: http://api.jquery.com/ready/

Upvotes: 5

uɥƃnɐʌuop
uɥƃnɐʌuop

Reputation: 15123

Well, basically, no. Whatever you put in there, it still gets called when the DOM loaded event is fired. For example, this:

$(undefined).ready(function() {
    alert("test");
});

Runs just like this:

$(document).ready(function() {
    alert("test");
});

Upvotes: 1

marcocamejo
marcocamejo

Reputation: 828

No, jQuery .ready() "Specify a function to execute when the DOM is fully loaded", so it cannot be used on any other element

Upvotes: 1

Related Questions