-
get( ) returns Array<Element>
Access all matched DOM elements.
This serves as a backwards-compatible way of accessing all matched elements (other than the jQuery object itself, which is, in fact, an array of elements).
It is useful if you need to operate on the DOM elements themselves instead of using built-in jQuery functions.Example:
Selects all divs in the document and returns the DOM Elements as an Array, then uses the built-in reverse-method to reverse that array.
function disp(divs) { var a = []; for (var i = 0; i < divs.length; i++) { a.push(divs[i].innerHTML); } $("span").text(a.join(" ")); } disp( $("div").get().reverse() );HTML:
Reversed - <span></span> <div>One</div> <div>Two</div> <div>Three</div> -
get( Number index ) returns Element
Access a single matched DOM element at a specified index in the matched set.
This allows you to extract the actual DOM element and operate on it directly without necessarily using jQuery functionality on it. This function called as $(this).get(0) is the equivalent of using square bracket notation on the jQuery object itself like $(this)[0].Example:
Gives the tag name of the element clicked on.
$("*", document.body).click(function (e) { e.stopPropagation(); var domEl = $(this).get(0); $("span:first").text("Clicked on - " + domEl.tagName); });HTML:
<span> </span> <p>In this paragraph is an <span>important</span> section</p> <div><input type="text" /></div> -
gt( Number index ) returns Array<Element>
Matches all elements with an index above the given one.
Example:
Finds TD #5 and higher. Reminder: the indexing starts at 0.
$("td:gt(4)").css("text-decoration", "line-through");HTML:
<table border="1"> <tr><td>TD #0</td><td>TD #1</td><td>TD #2</td></tr> <tr><td>TD #3</td><td>TD #4</td><td>TD #5</td></tr> <tr><td>TD #6</td><td>TD #7</td><td>TD #8</td></tr> </table>