Check if a node is a (certain) element
Last updated 5 years ago by wooorm .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install hast-util-is-element 
SYNC missed versions from official npm registry.


Build Coverage Downloads Size Sponsors Backers Chat

hast utility to check if a node is a (certain) element.



npm install hast-util-is-element


var is = require('hast-util-is-element')

is({type: 'text', value: 'foo'}) // => false

is({type: 'element', tagName: 'a'}, 'a') // => true

is({type: 'element', tagName: 'a'}, ['a', 'area']) // => true


isElement(node[, test[, index, parent[, context]]])

Check if the given value is a (certain) element.

  • node (Node) — Node to check.
  • test (Function, string, or Array.<Test>, optional) — When array, checks if any one of the subtests pass. When string, checks that the element has that tag name. When function, see test
  • index (number, optional) — Index of node in parent
  • parent (Node, optional) — Parent of node
  • context (*, optional) — Context object to invoke test with

boolean — Whether test passed and node is an Element.


Error — When an incorrect test, index, or parent is given. A node that is not a node, or not an element, does not throw.

function test(element[, index, parent])

  • element (Element) — Element to check
  • index (number?) — Index of node in parent
  • parent (Node?) — Parent of node

* — The to is given context.


boolean? — Whether element matches.


Create a test function from test, that can later be called with a node, index, and parent. Useful if you’re going to test many nodes, for example when creating a utility where something else passes a compatible test.

The created function is slightly faster because it expects valid input only. Therefore, passing invalid input, yields unexpected results.

Can also be accessed with require('hast-util-is-element/convert').


hast-util-is-element does not change the syntax tree so there are no openings for cross-site scripting (XSS) attacks.



See contributing.md in syntax-tree/.github for ways to get started. See support.md for ways to get help.

This project has a code of conduct. By interacting with this repository, organization, or community you agree to abide by its terms.


MIT © Titus Wormer

Current Tags

  • 1.1.0                                ...           latest (2 months ago)

6 Versions

  • 1.1.0                                ...           2 months ago
  • 1.0.4                                ...           8 months ago
  • 1.0.3                                ...           a year ago
  • 1.0.2                                ...           2 years ago
  • 1.0.1                                ...           2 years ago
  • 1.0.0                                ...           5 years ago
Maintainers (2)
Today 32
This Week 2,161
This Month 9,469
Last Day 386
Last Week 2,908
Last Month 13,508
Dependencies (0)
Dev Dependencies (13)
Dependents (63)

Copyright 2014 - 2016 © taobao.org |