开发者

Shorthand for just $(document) in jQuery

开发者 https://www.devze.com 2023-02-24 00:54 出处:网络
I noticed in the jQuery docs that as of 1.4, calling $() with no args just returns an empty set rather than $(document). http://api.jquery.com/jQuery/#returning-empty-set

I noticed in the jQuery docs that as of 1.4, calling $() with no args just returns an empty set rather than $(document). http://api.jquery.com/jQuery/#returning-empty-set

So, is there no other shorthand for $(document)?

I ask because I 开发者_C百科can't decide which is uglier if I'm trying to select an element by an ID that I have in a variable: $("#" + myID) or $(document).find(myId).

Thanks.


You always can make your own alias:

$d = $(document);


If you are selecting an element by an ID you should use $("#" + myID). $(document).find(myId) would be wrong.

0

精彩评论

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