Reputation: 122172
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
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
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
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