Underscore.js _.isElement() Method

Beginner
5 min read
Updated: Nov 2026
4 examples
Object

Definition

Returns true if object is a DOM element (official Underscore docs). Under the hood that means a truthy value with nodeType === 1.

Pass the required arguments shown below. Underscore object helpers usually return a new value — check whether the source object is mutated.

Syntax

Call _.isElement. Start with this line.

Underscore
_.isElement(object)
CallWhat it does
_.isElement(object)Primary signature.
_.isElement(...)Call with the arguments your case needs.

Load Underscore with import _ from "underscore" (or the UMD CDN build) so these helpers are available as _.

Library declarations
Underscore
_.isElement(object)

Parameters

ParameterDescription
objectRequired. Value to test

Return Value

Return ValueDescription
*true or false

Underscore.js Examples

Example 1 — Official Body Example

The docs use jQuery('body')[0]. Vanilla document.body is the same node.

Underscore
_.isElement(document.body);
// → true

_.isElement("body");
// → false
Try It Yourself

How It Works

  1. Body node. document.body is an element with nodeType === 1.
  2. Check. _.isElement(…) → true.
  3. String. "body" has no nodeType → false.
  4. jQuery tip. Use jQuery('body')[0] to unwrap the raw element.

Example 2 — createElement

A node does not have to be in the page. Detached elements still pass.

Underscore
console.log(_.isElement(document.createElement("div")));  // true
console.log(_.isElement(document.createElement("span"))); // true
Try It Yourself

How It Works

  1. Create a div. Still a real element node.
  2. Create a span. Same rule — nodeType is 1.
  3. Not attached? Does not matter for the type check.
  4. Takeaway. Any element node passes, in or out of the tree.

Example 3 — Other Node Types

Only nodeType === 1 passes. Text nodes and the document fail.

Underscore
var p = document.createElement("p");
p.textContent = "hi";

console.log(_.isElement(p));            // true  (nodeType 1)
console.log(_.isElement(p.firstChild)); // false (text node, type 3)
console.log(_.isElement(document));     // false (document, type 9)
Try It Yourself

How It Works

  1. Paragraph. Element node → passes.
  2. Text child. nodeType 3 → fails.
  3. document. nodeType 9 → fails.
  4. Rule. Elements only — not every DOM node.

Example 4 — Collections & Fakes

A NodeList is not an element. Underscore does not reject a forged nodeType.

Underscore
console.log(_.isElement(document.querySelector("body")));     // true
console.log(_.isElement(document.querySelectorAll("body")));  // false
console.log(_.isElement({ nodeType: 1 }));                    // true
Try It Yourself

How It Works

  1. querySelector. Returns one element → passes.
  2. querySelectorAll. Returns a NodeList → fails until you use [0].
  3. Fake object. Underscore’s duck-type check still returns true.
  4. Caution. Prefer real DOM nodes; Lodash rejects this forge.

Browser & Runtime Support

_.isElement ships with Underscore.js (1.x). It is most useful in browsers with a real DOM. In Node.js it still runs, but you need a DOM shim (e.g. jsdom) for real element values.

✓ Stable · Underscore 1.x

_.isElement()

Available in [email protected] (UMD / ESM). Works in evergreen browsers when Underscore is loaded. Node.js needs a DOM environment for meaningful element checks.

100% With Underscore 1.x + DOM
Google Chrome Supported · Desktop & Mobile
Full support
Mozilla Firefox Supported · Desktop & Mobile
Full support
Apple Safari Supported · macOS & iOS
Full support
Microsoft Edge Supported · Chromium
Full support
Internet Explorer No native support · Use a polyfill
Polyfill
Opera Supported · Modern versions
Full support
Samsung Internet Supported · Android
Full support
Bun Supported · JavaScript runtime
Supported
Deno Supported · JavaScript runtime
Supported
Node.js Supported · Server runtime
Supported
Android WebView Supported · Modern WebView
Full support
_.isElement Underscore 1.x+

Bottom line: Safe for browser production once Underscore is loaded. Not a native browser API — load Underscore first. Prefer a pinned CDN version (e.g. [email protected]).

Frequently Asked Questions

_.isElement(object) returns true when the value looks like a DOM element node — it is truthy and its nodeType is 1. That matches <div>, <span>, document.body, and SVG tags.
A jQuery object is a collection, not a DOM node. [0] (or .get(0)) unwraps the first raw element. _.isElement(jQuery('body')) is false; _.isElement(jQuery('body')[0]) is true. document.body is the vanilla equivalent.
No. Text nodes have nodeType 3, comments 8, documents 9, and fragments 11. Only element nodes (nodeType 1) pass.
Yes in Underscore. The helper is roughly !!(obj && obj.nodeType === 1). It does not prove the value came from the DOM. Lodash is stricter and rejects plain objects.
Yes. SVG elements are still element nodes with nodeType 1. The helper is not limited to HTML tag names.
No. It is a stable Underscore 1.x helper. Use it in the browser (or with a DOM shim such as jsdom) before treating a value as an element.

Next: _.isArray()

Detect real Arrays — useful when a NodeList looks like a list but is not one.

_.isArray() tutorial →

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.

10 people found this page helpful