Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is jQuery.ready useful on anything other than document?

Tags:

jquery

events

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?

like image 712
George Mauer Avatar asked Oct 08 '11 17:10

George Mauer


People also ask

Why do we need document ready jQuery?

The ready() method is used to make a function available after the document is loaded. Whatever code you write inside the $(document ). ready() method will run once the page DOM is ready to execute JavaScript code.

Can I use jQuery without document ready?

It is in no way required. All it does is make sure that the DOM is loaded before trying to query for and use the elements inside the DOM (usually after dom is ready and before body. onload fires). You can use jquery perfectly fine without it.

What does jQuery ready do?

jQuery | ready() with Examples The ready() method is an inbuilt method in jQuery which helps to load the whole page then execute the rest code. This method specify the function to execute when the DOM is fully loaded. Parameters: This method accepts single parameter function which is mandatory.

What can be used instead of document ready?

load(function(){ // ...}) @undefined, this is almost the same as $(document). ready(function(){ ... }) . load() will wait until the graphics are also loaded.


1 Answers

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/

like image 171
Eliasdx Avatar answered Dec 01 '22 01:12

Eliasdx