The get method is used to access the DOM elements in the jQuery object:
var allDivs = $("div").get();
In this example, allDivs will be an array containing all matched elements (in this case, it will contain every div element in the DOM).
The index method returns an integer that tells you the position of the selected item relative to its siblings. Consider the following HTML:
<ul> <li>1</li> <li id="second">2</li> <li>3</li> </ul>
And the following jQuery:
console.log($("#second").index())
As for your other question, the DOM node is almost anything in the DOM. Elements are node types (type 1). You also have, for example, text nodes (type 3). An element is just about any tag.
To make this clearer, consider the following HTML:
<div id="example"> Some text <div>Another div</div> </div>
And the following JS:
var div = $("#example").get(0); for(var i = 0; i < div.childNodes.length; i++) { console.log(div.childNodes[i].nodeType); }
This will print:
3 - Text node ("Some text") 1 - Element node (div) 3 - Text node ("Another div") 8 - Comment node () 3 - Text node ("A comment")
Here you can find a list of node types here . For an excellent introduction to the DOM in fact, see MDN Article
James allardice
source share