Bitcoin Forum
May 30, 2024, 04:55:04 AM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: jquery document.ready  (Read 1000 times)
payb.tc (OP)
Hero Member
*****
Offline Offline

Activity: 812
Merit: 1000



View Profile
November 13, 2011, 09: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.

captainteemo
Full Member
***
Offline Offline

Activity: 143
Merit: 101


View Profile
November 15, 2011, 05: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
btc_artist
Full Member
***
Offline Offline

Activity: 154
Merit: 101

Bitcoin!


View Profile WWW
November 15, 2011, 07: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.

BTC: 1CDCLDBHbAzHyYUkk1wYHPYmrtDZNhk8zf
LTC: LMS7SqZJnqzxo76iDSEua33WCyYZdjaQoE
payb.tc (OP)
Hero Member
*****
Offline Offline

Activity: 812
Merit: 1000



View Profile
November 15, 2011, 09: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.
btc_artist
Full Member
***
Offline Offline

Activity: 154
Merit: 101

Bitcoin!


View Profile WWW
November 15, 2011, 08: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.

BTC: 1CDCLDBHbAzHyYUkk1wYHPYmrtDZNhk8zf
LTC: LMS7SqZJnqzxo76iDSEua33WCyYZdjaQoE
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!