Tedderz
Tedderz

Reputation: 587

Shorthand for just $(document) in jQuery

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 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.

Upvotes: 1

Views: 131

Answers (2)

Sang Suantak
Sang Suantak

Reputation: 5265

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

Upvotes: 3

Daniel A. White
Daniel A. White

Reputation: 191037

You always can make your own alias:

$d = $(document);

Upvotes: 11

Related Questions