Author

Topic: jquery document.ready (Read 1017 times)

full member
Activity: 154
Merit: 102
Bitcoin!
November 15, 2011, 03:27:51 PM
#5
So the answer to your question is probably that people just copy example they see (the long version) and are oblivious to the fact that there's a more concise way to do it.
hero member
Activity: 812
Merit: 1000
November 15, 2011, 04:46:30 AM
#4
one waits for the page to complete loading, then do actions in the background. if you put this at the top of a page, with a slow thing, it waits for the page to finish
other fires wherever it hits (blocking, non-async) if you put this at the top of a page, it won't finish rendering until it returns

no, they are functionally identical... both only fire when the 'document' is 'ready'... one is just a shorter way of writing it, but i've seen hundreds of examples all over the web that has the longer version in it.
full member
Activity: 154
Merit: 102
Bitcoin!
November 15, 2011, 02:24:18 AM
#3
if these are 100% equivalent, why on earth would anyone ever use the longer version?

$(document).ready(handler)
$(handler)

i really wonder.


As far as I know, nobody uses the longer version.  It *is* self-documenting though, which is a plus I guess.
full member
Activity: 143
Merit: 101
November 15, 2011, 12:02:46 AM
#2
one waits for the page to complete loading, then do actions in the background. if you put this at the top of a page, with a slow thing, it waits for the page to finish
other fires wherever it hits (blocking, non-async) if you put this at the top of a page, it won't finish rendering until it returns
hero member
Activity: 812
Merit: 1000
November 13, 2011, 04:10:25 AM
#1
if these are 100% equivalent, why on earth would anyone ever use the longer version?

$(document).ready(handler)
$(handler)

i really wonder.

Jump to: