Skip to main content

Element

An element within the DOM.

Hierarchy

Index

Constructors

constructor

  • Parameters

    • name: string

      Name of the tag, eg. div, span.

    • attributes: NodeAttribute[]
    • children: ChildNode[] = []

      Children of the node.

    • type: Script | Style | Tag = ...

    Returns Element

Properties

publicattributes

attributes: NodeAttribute[]

publicchildren

children: ChildNode[]

Children of the node. Only certain node types can have children.

endIndex

endIndex: null | number = null

The end index of the node. Requires withEndIndices on the handler to be `true.

publicname

name: string

Name of the tag, eg. div, span.

optionalnamespace

namespace?: string

Element namespace (parse5 only).

next

next: null | ChildNode = null

Next sibling

parent

parent: null | ParentNode = null

Parent of the node

prev

prev: null | ChildNode = null

Previous sibling

optionalsourceCodeLocation

sourceCodeLocation?: null | TagSourceCodeLocation

parse5 source code location info, with start & end tags.

Available if parsing with parse5 and location info is enabled.

startIndex

startIndex: null | number = null

The start index of the node. Requires withStartIndices on the handler to be `true.

publictype

type: Script | Style | Tag = ...

The type of the node.

optionalx-attribsNamespace

x-attribsNamespace?: Record<string, string>

Element attribute namespaces (parse5 only).

optionalx-attribsPrefix

x-attribsPrefix?: Record<string, string>

Element attribute namespace-related prefixes (parse5 only).

Accessors

childNodes

  • Same as children. DOM spec-compatible alias.


    Returns ChildNode[]

  • Parameters

    Returns void

close

  • Node close tag details. Can be null for self closing tag


    Returns undefined | CharValue

  • Parameters

    Returns void

firstChild

  • First child of the node.


    Returns null | ChildNode

lastChild

  • Last child of the node.


    Returns null | ChildNode

loc

  • Node position in document


    Returns Range

  • Parameters

    Returns void

nextSibling

  • Same as next. DOM spec-compatible alias.


    Returns null | ChildNode

  • Parameters

    Returns void

nodeType

  • get nodeType(): 1
  • DOM spec-compatible node type.


    Returns 1

open

  • Node open tag details


    Returns CharValue

  • Parameters

    Returns void

parentNode

  • Same as parent. DOM spec-compatible alias.


    Returns null | ParentNode

  • Parameters

    Returns void

previousSibling

  • Same as prev. DOM spec-compatible alias.


    Returns null | ChildNode

  • Parameters

    Returns void

tagName

  • get tagName(): string
  • set tagName(name: string): void
  • Same as name. DOM spec-compatible alias.


    Returns string

  • Parameters

    • name: string

    Returns void

Methods

cloneNode

  • cloneNode<T>(this: T, recursive?: boolean): T
  • Clone this node, and optionally its children.


    Type parameters

    Parameters

    • this: T
    • recursive: boolean = false

      Clone child nodes as well.

    Returns T

    A clone of the node.