or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

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

0

# lodash.iselement

1

2

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.

3

4

## Package Information

5

6

- **Package Name**: lodash.iselement

7

- **Package Type**: npm

8

- **Language**: JavaScript (CommonJS)

9

- **Installation**: `npm install lodash.iselement`

10

11

## Core Imports

12

13

```javascript

14

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

15

```

16

17

## Basic Usage

18

19

```javascript

20

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

21

22

// Check DOM elements

23

isElement(document.body);

24

// => true

25

26

isElement(document.createElement('div'));

27

// => true

28

29

// Check non-DOM values

30

isElement('<body>');

31

// => false

32

33

isElement({ nodeType: 1 });

34

// => false (plain object, not a DOM element)

35

36

isElement(null);

37

// => false

38

39

isElement([1, 2, 3]);

40

// => false

41

```

42

43

## Capabilities

44

45

### DOM Element Detection

46

47

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.

48

49

```javascript { .api }

50

/**

51

* Checks if `value` is likely a DOM element.

52

*

53

* @static

54

* @memberOf _

55

* @since 0.1.0

56

* @category Lang

57

* @param {*} value The value to check.

58

* @returns {boolean} Returns `true` if `value` is a DOM element, else `false`.

59

* @example

60

*

61

* _.isElement(document.body);

62

* // => true

63

*

64

* _.isElement('<body>');

65

* // => false

66

*/

67

function isElement(value);

68

```

69

70

**Implementation Details:**

71

72

The function performs the following checks:

73

1. **Truthy check**: Ensures the value is not null, undefined, or falsy

74

2. **NodeType check**: Verifies `value.nodeType === 1` (Element node type)

75

3. **Object-like check**: Confirms the value is object-like (not null and typeof "object")

76

4. **Plain object exclusion**: Ensures the value is not a plain object created by Object constructor

77

78

**Browser Compatibility:**

79

80

- Works in all modern browsers

81

- Includes legacy IE compatibility for host objects

82

- Safe property access patterns prevent errors in edge cases

83

- No external dependencies required

84

85

**Usage Examples:**

86

87

```javascript

88

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

89

90

// DOM elements

91

console.log(isElement(document.body)); // => true

92

console.log(isElement(document.createElement('span'))); // => true

93

console.log(isElement(document.documentElement)); // => true

94

95

// Non-DOM elements

96

console.log(isElement(document)); // => false (Document node, not Element)

97

console.log(isElement(document.createTextNode('text'))); // => false (Text node)

98

console.log(isElement(document.createComment('comment'))); // => false (Comment node)

99

100

// Plain objects and other values

101

console.log(isElement({})); // => false

102

console.log(isElement({ nodeType: 1 })); // => false (plain object)

103

console.log(isElement('string')); // => false

104

console.log(isElement(123)); // => false

105

console.log(isElement([])); // => false

106

console.log(isElement(null)); // => false

107

console.log(isElement(undefined)); // => false

108

```

109

110

**Error Handling:**

111

112

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

113

- Null and undefined values return false

114

- Primitive values (strings, numbers, booleans) return false

115

- Objects without nodeType property return false

116

- Host objects in legacy browsers are handled safely