开发者

jQuery document ready functions

开发者 https://www.devze.com 2023-04-06 05:13 出处:网络
what are the differences (if any) for the following jQue开发者_开发知识库ry document ready functions:

what are the differences (if any) for the following jQue开发者_开发知识库ry document ready functions:

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


They are equivalent, the later is a shorthand form for the first.

From the jQuery documentation:

All three of the following syntaxes are equivalent:

$(document).ready(handler)
$().ready(handler) (this is not recommended)
$(handler)


The only difference is brevity. http://api.jquery.com/jQuery/#jQuery3

jQuery( callback )

This function behaves just like $(document).ready(), in that it should be used to wrap other $() operations on your page that depend on the DOM being ready. While this function is, technically, chainable, there really isn't much use for chaining against it.

(emphasis added)


They are the same. Check out: http://api.jquery.com/jQuery/#jQuery3


They're the same; as stated earlier, the latter is merely a shorthand version of the former.

I prefer using the expanded version, as I feel it makes code easier to read.


Its the same. Different names to do the same thing


$(afunc) just calls $(document).ready(afunc); after 4 if statements which don't get entered since afunc is a function.


$(document).ready(function(){})
$().ready(function(){}) (this is not recommended)
$(function(){})
0

精彩评论

暂无评论...
验证码 换一张
取 消