Lesson. You need a real DOM element, not a lookalike.
Compatibility
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-firstWith a DOM available
Google ChromeSupported · Desktop & Mobile
Full support
Mozilla FirefoxSupported · Desktop & Mobile
Full support
Apple SafariSupported · macOS & iOS
Full support
Microsoft EdgeSupported · Chromium
Full support
Internet ExplorerNo native support · Use a polyfill
Polyfill
OperaSupported · Modern versions
Full support
Samsung InternetSupported · Android
Full support
BunSupported · JavaScript runtime
Supported
DenoSupported · JavaScript runtime
Supported
Node.jsSupported · Server runtime
Supported
Android WebViewSupported · Modern WebView
Full support
_.isElementLodash 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.