Haroldo
Haroldo

Reputation: 37377

what is the sequence of jquery pageload events?

are there any good guides as to which events happen in which order (and what triggers them)?

ie:

$(document).ready
$(window).ready
$(window).onload

EDIT: are there any other (pageload) events that i'm missing?

Upvotes: 1

Views: 3577

Answers (5)

rodrigot
rodrigot

Reputation: 142

All answers are right, but just to clarify.

It's window.onload or $(window).load

There's no $(window).onload nor window.load

Upvotes: 0

stoic
stoic

Reputation: 4830

as far as i know

  1. $(document).ready
  2. $(window).onload

Upvotes: 0

Nick Craver
Nick Craver

Reputation: 630569

  1. document.ready - DOM Elements good to go
    • Triggered by DOMContentLoaded in Mozilla/WebKit/Opera
    • Trigered by onreadystatechange in IE
  2. window.load - Images loaded
    • The actual window.onload event, this is a core DOM event, not created by jQuery.

document.ready happens before or when window.load does...if all else fails, document.ready is actually an event handler on window.load, you can see the source code here: http://github.com/jquery/jquery/blob/master/src/core.js#L407

There isn't a window.ready, document.ready is a special event that jQuery creates, only for document and not window.

Upvotes: 6

Pekka
Pekka

Reputation: 449683

  • $(document).ready when the browser is done rendering the DOM (the HTML file)

  • $(window).ready never heard of that one. Don't think it exists

  • $(window).onload when every linked resource on the page (including images) was loaded (usually some time after document.ready)

Upvotes: 4

gblazex
gblazex

Reputation: 50109

  1. $(document).ready
  2. $(window).onload (document + multimedia (like images))

There isn't $(window).ready

Upvotes: 3

Related Questions