Class Element

An element within the DOM.

Hierarchy

  • NodeWithChildren
    • Element

Constructors

  • Parameters

    • name: string

      Name of the tag, eg. div, span.

    • attribs: {
          [name: string]: string;
      }

      Object mapping attribute names to attribute values.

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

      Children of the node.

    • Optional type: Script | Style | Tag

    Returns Element

Properties

attribs: {
    [name: string]: string;
}

Type declaration

  • [name: string]: string
children: ChildNode[]
endIndex: null | number

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

name: string
namespace?: string

Element namespace (parse5 only).

next: null | ChildNode

Next sibling

parent: null | ParentNode

Parent of the node

prev: null | ChildNode

Previous sibling

sourceCodeLocation?: null | TagSourceCodeLocation

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

Available if parsing with parse5 and location info is enabled.

startIndex: null | number

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

type: Script | Style | Tag
x-attribsNamespace?: Record<string, string>

Element attribute namespaces (parse5 only).

x-attribsPrefix?: Record<string, string>

Element attribute namespace-related prefixes (parse5 only).

Accessors

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

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

    Returns ChildNode[]

  • set childNodes(children: ChildNode[]): void
  • Parameters

    • children: ChildNode[]

    Returns void

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

    Returns null | ChildNode

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

    Returns null | ChildNode

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

    Returns null | ChildNode

  • set nextSibling(next: null | ChildNode): void
  • Parameters

    • next: null | ChildNode

    Returns void

  • get nodeType(): 1
  • Returns 1

  • get parentNode(): null | ParentNode
  • Same as parent. DOM spec-compatible alias.

    Returns null | ParentNode

  • set parentNode(parent: null | ParentNode): void
  • Parameters

    Returns void

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

    Returns null | ChildNode

  • set previousSibling(prev: null | ChildNode): void
  • Parameters

    • prev: null | ChildNode

    Returns void

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

    Returns string

  • set tagName(name: string): void
  • Parameters

    • name: string

    Returns void

Methods

  • Clone this node, and optionally its children.

    Returns

    A clone of the node.

    Type Parameters

    Parameters

    • this: T
    • Optional recursive: boolean

      Clone child nodes as well.

    Returns T