or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

index.md
tile.json

tessl/npm-lodash--iselement

The lodash method isElement exported as a module for detecting DOM elements in JavaScript.

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
npmpkg:npm/lodash.iselement@4.1.x

To install, run

npx @tessl/cli install tessl/npm-lodash--iselement@4.1.0

index.mddocs/

lodash.iselement

The lodash method isElement exported as a standalone module for detecting DOM elements in JavaScript. This utility function provides reliable DOM element detection with comprehensive type checking and legacy browser compatibility.

Package Information

  • Package Name: lodash.iselement
  • Package Type: npm
  • Language: JavaScript (CommonJS)
  • Installation: npm install lodash.iselement

Core Imports

const isElement = require('lodash.iselement');

Basic Usage

const isElement = require('lodash.iselement');

// Check DOM elements
isElement(document.body);
// => true

isElement(document.createElement('div'));
// => true

// Check non-DOM values
isElement('<body>');
// => false

isElement({ nodeType: 1 });
// => false (plain object, not a DOM element)

isElement(null);
// => false

isElement([1, 2, 3]);
// => false

Capabilities

DOM Element Detection

Checks if a value is likely a DOM element by verifying it has the correct nodeType, is object-like, and is not a plain object.

/**
 * Checks if `value` is likely a DOM element.
 * 
 * @static
 * @memberOf _
 * @since 0.1.0
 * @category Lang
 * @param {*} value The value to check.
 * @returns {boolean} Returns `true` if `value` is a DOM element, else `false`.
 * @example
 * 
 * _.isElement(document.body);
 * // => true
 * 
 * _.isElement('<body>');
 * // => false
 */
function isElement(value);

Implementation Details:

The function performs the following checks:

  1. Truthy check: Ensures the value is not null, undefined, or falsy
  2. NodeType check: Verifies value.nodeType === 1 (Element node type)
  3. Object-like check: Confirms the value is object-like (not null and typeof "object")
  4. Plain object exclusion: Ensures the value is not a plain object created by Object constructor

Browser Compatibility:

  • Works in all modern browsers
  • Includes legacy IE compatibility for host objects
  • Safe property access patterns prevent errors in edge cases
  • No external dependencies required

Usage Examples:

const isElement = require('lodash.iselement');

// DOM elements
console.log(isElement(document.body)); // => true
console.log(isElement(document.createElement('span'))); // => true
console.log(isElement(document.documentElement)); // => true

// Non-DOM elements
console.log(isElement(document)); // => false (Document node, not Element)
console.log(isElement(document.createTextNode('text'))); // => false (Text node)
console.log(isElement(document.createComment('comment'))); // => false (Comment node)

// Plain objects and other values
console.log(isElement({})); // => false
console.log(isElement({ nodeType: 1 })); // => false (plain object)
console.log(isElement('string')); // => false
console.log(isElement(123)); // => false
console.log(isElement([])); // => false
console.log(isElement(null)); // => false
console.log(isElement(undefined)); // => false

Error Handling:

The function never throws errors and gracefully handles all input types:

  • Null and undefined values return false
  • Primitive values (strings, numbers, booleans) return false
  • Objects without nodeType property return false
  • Host objects in legacy browsers are handled safely