jquery: Choosing a document.ready method

后端 未结 2 1789
太阳男子
太阳男子 2021-01-21 01:48

I\'m new to jquery. I\'ve just read that these 2 are equivalent:

$(document).ready(function() {});

$(function() {});

Which one

相关标签:
2条回答
  • 2021-01-21 02:08

    Feel free to use either one of them. Just as you think, the latter version is a shorthand for $(document).ready().

    The first option was available since the beginning of jQuery releases as oppose to the second option.

    Personally I prefer the second version for it is shorter.

    0 讨论(0)
  • All three of the following syntaxes are equivalent:

    $(document).ready(handler);
    
    $().ready(handler); //(this is not recommended)
    
    $(handler);
    
    0 讨论(0)
提交回复
热议问题