I’m lead to this question when trying to figure out the difference between jQuery’s .get() and .index(), I’ve looked over the jQuery API and I still don’t get what the difference is between them, maybe i’m not understanding the terminology?
What’s the difference between a jQuery object and a DOM element? And are a DOM element and a DOM node the same thing? Are they just <div> and <a> etc. is a DOM node/DOM element just an HTML tag?
EDIT: and isn’t the DOM just the structure of the page? <html><body>etc.</body></html>?
The
getmethod is used to access the DOM elements within a jQuery object:In that example,
allDivswill be an array containing all the matched elements (in this case, it would contain everydivelement in the DOM).The
indexmethod returns an integer that tells you the position of the selected element relative to its siblings. Consider the following HTML:And the following jQuery:
As for your other question, a DOM node is pretty much anything in the DOM. Elements are types of nodes (type 1). You also have, for example, text nodes (type 3). An element is pretty much any tag.
To make that clearer, consider the following HTML:
And the following JS:
That will print out:
You can find a list of node types here. For an excellent introduction to what the DOM actually is, see this MDN article