Lodash _.isElement() Method

Beginner
5 min read
Updated: Nov 2026
5 examples
Lang

Definition

Checks if value is likely a DOM element — object-like, nodeType === 1, and not a Lodash plain object. Since Lodash 0.1.0.

Pass the value you want to inspect or convert. Read the return type carefully before you use the result.

Syntax

Call _.isElement. Start with this line.

Lodash
_.isElement(value)
CallWhat it does
_.isElement(value)Primary signature.

Prefer import isElement from "lodash/isElement" when you want a smaller bundle.

Library declarations
Lodash
_.isElement(value)

Parameters

ParameterDescription
valueRequired. The value to check

Return Value

Return ValueDescription
*true if likely a DOM element

Lodash Examples

Example 1 — Official: document.body

A live element node passes the check.

Lodash
_.isElement(document.body);
// → true
Try It Yourself

How It Works

  1. body is an HTML element in the document.
  2. nodeType is 1 (ELEMENT_NODE).
  3. Not a plain object literal.
  4. Result. true.

Example 2 — Official: HTML String

Markup text is not a DOM element.

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

How It Works

  1. Input is a string of characters.
  2. No nodeType — not a Node.
  3. Result. false.
  4. Parse into the DOM (e.g. createElement / parser) if you need a real node.

Example 3 — createElement

Elements you create are valid even before they are attached.

Lodash
_.isElement(document.createElement("div"));
// → true

_.isElement(document.createElement("span"));
// → true
Try It Yourself

How It Works

  1. createElement returns an element node.
  2. nodeType is already 1.
  3. Attachment to the document is not required.
  4. Same for SVG via createElementNS.

Example 4 — Text Node Is Not an Element

Other node types fail even though they are Nodes.

Lodash
var text = document.createTextNode("hi");

_.isElement(text);
// → false

text.nodeType;
// → 3  (TEXT_NODE)
Try It Yourself

How It Works

  1. Text nodes are Nodes with nodeType 3.
  2. isElement requires nodeType === 1.
  3. Result. false.
  4. Comments (nodeType 8) also fail.

Example 5 — Duck-Typed Plain Object

A forged { nodeType: 1 } does not pass.

Lodash
_.isElement({ nodeType: 1 });
// → false

_.isPlainObject({ nodeType: 1 });
// → true  (why the fake fails)
Try It Yourself

How It Works

  1. Object literal looks similar at a glance.
  2. isPlainObject is true for that shape.
  3. isElement rejects plain objects on purpose.
  4. Lesson. You need a real DOM element, not a lookalike.

Browser & Runtime Support

_.isElement is a Lodash Lang helper (since 0.1.0). It is useful in browsers (and Node only with a DOM shim). Lodash itself loads everywhere; detecting elements requires document / Node hosts.

✓ Stable · Lodash 0.1.0+

_.isElement()

Available in [email protected] full builds and the lodash/isElement modular import. Best in evergreen browsers; use jsdom (or similar) on the server.

Browser-first With a DOM available
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 Lodash 0.1.0+

Bottom line: Safe in browser apps once Lodash is loaded. Prefer import isElement from "lodash/isElement" for smaller builds. On the server, provide a DOM before expecting true results.

Frequently Asked Questions

_.isElement(value) returns true if value is likely a DOM element — object-like, nodeType === 1, and not a Lodash plain object. Otherwise it returns false.
No. Text nodes use nodeType 3 and comments use 8. Only element nodes (nodeType 1) pass.
No. Lodash also rejects values classified as plain objects, so { nodeType: 1 } fails.
Yes. SVG elements in the DOM still have nodeType 1 — the check is not limited to HTML tag names.
Not usefully — there are no DOM elements. Use a browser, or a DOM shim such as jsdom, if you need this check on the server.
Use import isElement from "lodash/isElement" or require("lodash/isElement") for tree-shaking. Full build: import _ from "lodash" then _.isElement.

Next: _.isEmpty()

Check whether collections, strings, Maps, and Sets are empty.

_.isEmpty() 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.

11 people found this page helpful