Skip to content

Create "What is a jQuery Object" article #95

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
ajpiano opened this issue Mar 23, 2012 · 2 comments
Closed

Create "What is a jQuery Object" article #95

ajpiano opened this issue Mar 23, 2012 · 2 comments

Comments

@ajpiano
Copy link
Member

ajpiano commented Mar 23, 2012

A straightforward explanation of exactly what a jQuery object is (an array of DOM elements "wrapped" with jQuery's methods) and explain some very common mistakes newcomers make with respect to knowing the difference between a jQuery object and a native DOM element.

Explain why all of these fail:

$("#foo").innerHtml = "bar"; // using a native DOM property on a jQuery object
$(".bar")[0].text("hello"); // using a jQuery method on a native DOM element

Explain why jQuery objects always are array-like, even when querying for an element by ID. (This question comes up frequently).

Touch on the major methods for going back and forth between jQuery and native DOM (get, eq) and testing if a jQuery object contains any elements (.length).

Explain that jQuery objects are not "live" collections

Explain that jQuery objects are transient, even if they contain the same elements, cannot ever be compared for equality. (Borrow and expand upon this slide

Bonus Material: Expain why jQuery objects print as arrays in Developer Tools (they have a .splice method and a .length property). Explain how the .length property of a jQuery set is manually maintained within jQuery (perhaps too advanced for this article?)

@kswedberg
Copy link
Member

Great ideas here, Adam! Regarding "explain how the .length property of a jQuery set is manually maintained," maybe it's enough in this article to just say that it is manually maintained within jQuery — to ward off the possible assumption of beginners that it is somehow maintained "automagically." Just a thought.

@ajpiano
Copy link
Member Author

ajpiano commented Mar 23, 2012

+1 to that for now!

jugglinmike added a commit to jugglinmike/learn.jquery.com that referenced this issue Apr 22, 2012
jugglinmike added a commit to jugglinmike/learn.jquery.com that referenced this issue May 20, 2012
@ajpiano ajpiano closed this as completed Oct 15, 2012
arthurvr pushed a commit to arthurvr/learn.jquery.com that referenced this issue Jan 4, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

2 participants