jQuery .get() Method

Beginner
5 min read
Updated: Nov 2026
3 examples
DOM

Definition

.get() retrieves the raw DOM elements behind a jQuery object (since jQuery 1.0). .get(index) returns a single Element (or undefined); .get() with no argument returns every matched element as a native Array. This is the DOM-retrieval method — not $.get(), the Ajax helper.

Syntax

Start with these common calls. Keep them short and readable.

jQuery
$(selector).get()        → Array of DOM elements
$(selector).get(index)   → one DOM Element, or undefined

$("li").get(1)           // 2nd element (zero-based)
$("li").get(-1)          // last element (negative counts from the end)
$("li").get(99)          // undefined — out of range
$("li").get()            // [li, li, li] native Array

// Same node as the array dereference:
$("li").get(0) === $("li")[0]   // true
CallWhat it does
.get()Native Array of every matched DOM element
.get(index)One DOM Element at that zero-based position
.get(-n)Counts back from the end: -1 is the last element
Out of rangeReturns undefined (no error is thrown)
SincejQuery 1.0

Load jQuery before your script (CDN or local file), then wrap DOM work in $(function () { ... }) when needed.

Parameters

ParameterDescription
index (optional)Integer position of the element to retrieve. Zero-based; negative values count back from the end of the set. Omit it to get all elements as an Array.

Return Value

Return ValueDescription
Element.get(index) returns the DOM element at that position — a plain node, not a jQuery object.
undefined.get(index) returns undefined when the index is out of range or the set is empty.
Array.get() with no argument returns a new native Array of DOM elements (same idea as .toArray()).

jQuery Examples

Example 1 — Get One Element by Index

Read a raw DOM element from the set and inspect it.

jQuery
var el = $("li").get(1);

console.log(el.tagName);          // LI
console.log(el.textContent);      // Banana
console.log(el === $("li")[1]);   // true
Try It Yourself

How It Works

  1. Select. $("li") matches Apple, Banana, and Cherry.
  2. Retrieve. .get(1) returns the second node (zero-based).
  3. Compare. It is the exact same node as $("li")[1].

Example 2 — Negative and Out-of-Range Indexes

Count from the end, and see what happens past the edge of the set.

jQuery
var $li = $("li");   // Apple, Banana, Cherry

console.log($li.get(-1).textContent);  // Cherry
console.log($li.get(-3).textContent);  // Apple
console.log($li.get(99));              // undefined
Try It Yourself

How It Works

  1. From the end. -1 is the last element; -3 is the first of three.
  2. Out of range. .get(99) returns undefined.
  3. Guard. Check the result before reading properties to avoid a TypeError.

Example 3 — .get() as an Array

Call .get() with no argument to get a native Array and use Array methods.

jQuery
var arr = $("li").get();

console.log(Array.isArray(arr));   // true
console.log(arr.length);           // 3

var labels = arr.map(function (el) {
  return el.textContent;
});
console.log(labels.join(", "));    // Apple, Banana, Cherry
Try It Yourself

How It Works

  1. Convert. .get() returns a real Array of DOM nodes.
  2. Inspect. Array.isArray is true and the length is 3.
  3. Map. Native map turns each node into its text.

Frequently Asked Questions

.get() retrieves the raw DOM elements behind a jQuery object. .get(index) returns one Element (or undefined); .get() with no arguments returns all matched elements as a native Array. Available since jQuery 1.0.
No. $.get() is the Ajax helper that sends an HTTP GET request. The .get() method on a jQuery collection only reads DOM elements and makes no network request.
.eq(index) returns a jQuery object, so you can keep chaining jQuery methods. .get(index) returns the raw DOM element (or undefined), so you use native properties such as textContent.
.get() with no arguments and .toArray() both return a native Array of DOM elements. .get(index) additionally lets you pick a single element, including with a negative index.
Yes. .get(-1) returns the last element and .get(-2) the second from last. An index beyond either end returns undefined.
Yes. $("li").get(0) and $("li")[0] return the same DOM node. Bracket access is shorter, but .get() also accepts negative indexes and can return the whole array.

Next: .toArray() Method

Convert the entire jQuery set into a native Array of DOM elements.

.toArray() Method tutorial →

CODETOFUN NEWS

Stay Ahead in Tech

Get the latest IT news, programming updates, and technology trends directly on your phone.

Your daily dose of tech, straight to your feed.

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

9 people found this page helpful