Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Element

Re-exporting all of the node types.

Hierarchy

Index

Constructors

constructor

  • new Element(name: string, attribs: {}, children?: Node[], type?: Script | Style | Tag): Element
  • Parameters

    • name: string

      Name of the tag, eg. div, span.

    • attribs: {}

      Object mapping attribute names to attribute values.

      • [name: string]: string
    • Optional children: Node[]

      Children of the node.

    • Optional type: Script | Style | Tag

    Returns Element

Properties

attribs

attribs: {}

Type declaration

  • [name: string]: string

children

children: Node[]

endIndex

endIndex: null | number

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

name

name: string

Optional namespace

namespace?: string

Element namespace (parse5 only).

next

next: null | Node

Next sibling

parent

parent: null | NodeWithChildren

Parent of the node

prev

prev: null | Node

Previous sibling

Optional sourceCodeLocation

sourceCodeLocation?: { endColumn: number; endLine: number; endOffset: number; startColumn: number; startLine: number; startOffset: number }

parse5 source code location info.

Available if parsing with parse5 and location info is enabled.

Type declaration

  • endColumn: number
  • endLine: number
  • endOffset: number
  • startColumn: number
  • startLine: number
  • startOffset: number

startIndex

startIndex: null | number

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

type

type: ElementType

Optional x-attribsNamespace

x-attribsNamespace?: Record<string, string>

Element attribute namespaces (parse5 only).

Optional x-attribsPrefix

x-attribsPrefix?: Record<string, string>

Element attribute namespace-related prefixes (parse5 only).

Accessors

attributes

  • get attributes(): Attribute[]
  • Returns Attribute[]

childNodes

  • get childNodes(): Node[]
  • set childNodes(children: Node[]): void
  • Same as children. DOM spec-compatible alias.

    Returns Node[]

  • Same as children. DOM spec-compatible alias.

    Parameters

    Returns void

firstChild

  • get firstChild(): null | Node
  • First child of the node.

    Returns null | Node

lastChild

  • get lastChild(): null | Node
  • Last child of the node.

    Returns null | Node

nextSibling

  • get nextSibling(): null | Node
  • set nextSibling(next: null | Node): void
  • Same as next. DOM spec-compatible alias.

    Returns null | Node

  • Same as next. DOM spec-compatible alias.

    Parameters

    Returns void

nodeType

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

    Returns number

parentNode

  • Same as parent. DOM spec-compatible alias.

    Returns null | NodeWithChildren

  • Same as parent. DOM spec-compatible alias.

    Parameters

    Returns void

previousSibling

  • get previousSibling(): null | Node
  • set previousSibling(prev: null | Node): void
  • Same as prev. DOM spec-compatible alias.

    Returns null | Node

  • Same as prev. DOM spec-compatible alias.

    Parameters

    Returns void

tagName

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

    Returns string

  • Same as name. DOM spec-compatible alias.

    Parameters

    • name: string

    Returns void

Methods

cloneNode

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

    Type parameters

    Parameters

    • Optional recursive: boolean

      Clone child nodes as well.

    Returns T

    A clone of the node.