omg
omg

Reputation: 140132

Is there a native Javascript implementation of jQuery's document.ready()?

 $(document).onload()

it's internally implemented by window.onload event

then what about

 $(document).ready()

what's the native javascript to implement it?

Upvotes: 8

Views: 6826

Answers (3)

Christian C. Salvadó
Christian C. Salvadó

Reputation: 828200

For Mozilla, Opera and webkit, jQuery binds the DOMContentLoaded event, for IE jQuery uses the onreadystatechange event.

Look the internal bindReady function on the jQuery source code.

Upvotes: 18

Greg Hewgill
Greg Hewgill

Reputation: 994947

Looking at the jQuery source code, there is a function called bindReady that does the native Javascript work. There are different methods for different browsers, and the fallback method if none of the specific methods work is to use the window.onload event.

Upvotes: 1

Noon Silk
Noon Silk

Reputation: 55182

What do you mean?

.ready() is a function jQuery wrote to handle the inconsistent way that all the browsers may report 'load complete' for the given element.

.onload() may work in X browser but not Y. This is (part) of what jQuery is for - to solve this problem for you.

Upvotes: 1

Related Questions