Options
All
  • Public
  • Public/Protected
  • All
Menu

Class NodeWithChildren

Base type for any type of node that can have children

Hierarchy

Index

Constructors

constructor

Properties

childNodes

childNodes: Node[] = []

Children of this node. Do not modify this directly, use NodeLogic or instance methods.

nextSibling

nextSibling: null | Node = null

Next sibling node, or null if none exists. Do not modify this directly, use NodeLogic or instance methods.

Readonly nodeData

nodeData: Record<PropertyKey, unknown> = {}

Extra DOM data associated with this node. This object prototypically inherits from the parent node's nodeData.

Readonly nodeTags

nodeTags: Set<string> = ...

Set of unique string tags applied to this node. These tags do not inherit and are unique to each instance. Meaning is tag-specific.

Readonly nodeType

nodeType: NodeType

Type of this node

parentNode

parentNode: null | NodeWithChildren = null

Parent of this node, or null if there is none. Do not modify this directly, use NodeLogic or instance methods.

prevSibling

prevSibling: null | Node = null

Previous sibling node, or null if none exists. Do not modify this directly, use NodeLogic or instance methods.

Accessors

firstChild

  • get firstChild(): null | Node
  • The first child node of this parent, or null if there are no children.

    Returns null | Node

firstChildTag

  • get firstChildTag(): null | TagNode

firstChildText

lastChild

  • get lastChild(): null | Node
  • The last child node of this parent, or null if there are no children.

    Returns null | Node

lastChildTag

  • get lastChildTag(): null | TagNode

lastChildText

nextSiblingTag

  • get nextSiblingTag(): null | TagNode
  • The closest following sibling that is a TagNode, or null if none exists.

    Returns null | TagNode

nextSiblingText

  • get nextSiblingText(): null | TextNode

prevSiblingTag

  • get prevSiblingTag(): null | TagNode
  • The closest previous sibling that is a TagNode, or null if none exists.

    Returns null | TagNode

prevSiblingText

  • get prevSiblingText(): null | TextNode

Methods

appendChild

  • appendChild(child: Node): void
  • Inserts a child at the end of this parent's children

    Parameters

    • child: Node

      Node to insert

    Returns void

appendChildren

  • appendChildren(children: Node[]): void
  • Append multiple children to the end of this parent's child list

    Parameters

    • children: Node[]

      Child nodes to append. Can be empty.

    Returns void

appendSibling

  • appendSibling(node: Node): void

clear

  • clear(): void

Abstract clone

  • clone(deep?: boolean, callback?: (oldNode: Node, newNode: Node) => void): Node
  • Clone this node

    Parameters

    • Optional deep: boolean

      If true, child nodes will be cloned

    • Optional callback: (oldNode: Node, newNode: Node) => void

      Optional callback for each node after cloning

        • Parameters

          Returns void

    Returns Node

    The generated clone

createDomFromChildren

  • Removes all children from this node and creates a new DocumentNode containing them.

    Returns DocumentNode

    the created DocumentNode

findChildNode

  • findChildNode(matcher: (node: Node) => boolean, deep?: boolean): null | Node
  • Finds the first child node that matches a condition. Returns null if no match found.

    Parameters

    • matcher: (node: Node) => boolean

      Callback to test condition

        • (node: Node): boolean
        • Parameters

          Returns boolean

    • deep: boolean = true

      If true, children of child nodes will also be searched.

    Returns null | Node

    First matching child, or null

findChildNodeByNodeType

findChildNodes

  • findChildNodes(matcher: (node: Node) => boolean, deep?: boolean): Node[]
  • Finds all child nodes that match a condition. Returns an empty array if no matches found.

    Parameters

    • matcher: (node: Node) => boolean

      Callback to test condition

        • (node: Node): boolean
        • Parameters

          Returns boolean

    • deep: boolean = true

      If true, children of child nodes will also be searched.

    Returns Node[]

    Array of all Nodes that match condition

findChildNodesByNodeType

findChildTag

  • findChildTag(matcher: (tag: TagNode) => boolean, deep?: boolean): null | TagNode
  • Finds the first child TagNode that matches a condition. Returns null if no match found.

    Parameters

    • matcher: (tag: TagNode) => boolean

      Callback to test condition

    • deep: boolean = true

      If true, children of child nodes will also be searched.

    Returns null | TagNode

    First TagNode that matches the condition, or null.

findChildTagByTagName

  • findChildTagByTagName(tagName: "m-fragment", deep?: boolean): null | MFragmentNode
  • findChildTagByTagName(tagName: "m-content", deep?: boolean): null | MContentNode
  • findChildTagByTagName(tagName: "m-slot", deep?: boolean): null | MSlotNode
  • findChildTagByTagName(tagName: "m-var", deep?: boolean): null | MVarNode
  • findChildTagByTagName(tagName: "m-scope", deep?: boolean): null | MScopeNode
  • findChildTagByTagName(tagName: "m-import", deep?: boolean): null | MImportNode
  • findChildTagByTagName(tagName: "m-if", deep?: boolean): null | MIfNode
  • findChildTagByTagName(tagName: "m-for", deep?: boolean): null | MForNode
  • findChildTagByTagName(tagName: "m-data", deep?: boolean): null | MDataNode
  • findChildTagByTagName(tagName: "style", deep?: boolean): null | StyleNode
  • findChildTagByTagName(tagName: "script", deep?: boolean): null | ScriptNode
  • findChildTagByTagName(tagName: "a", deep?: boolean): null | AnchorNode
  • findChildTagByTagName(tagName: "m-whitespace", deep?: boolean): null | MWhitespaceNode
  • findChildTagByTagName(tagName: string, deep?: boolean): null | TagNode

findChildTags

  • findChildTags(matcher: (tag: TagNode) => boolean, deep?: boolean): TagNode[]
  • Finds all child TagNodes that match a condition. Returns an empty array if no matches found.

    Parameters

    • matcher: (tag: TagNode) => boolean

      Callback to test condition

    • deep: boolean = true

      If true, children of child nodes will also be searched.

    Returns TagNode[]

    Array of all TagNodes that match condition

findChildTagsByTagName

  • findChildTagsByTagName(tagName: "m-fragment", deep?: boolean): MFragmentNode[]
  • findChildTagsByTagName(tagName: "m-content", deep?: boolean): MContentNode[]
  • findChildTagsByTagName(tagName: "m-slot", deep?: boolean): MSlotNode[]
  • findChildTagsByTagName(tagName: "m-var", deep?: boolean): MVarNode[]
  • findChildTagsByTagName(tagName: "m-scope", deep?: boolean): MScopeNode[]
  • findChildTagsByTagName(tagName: "m-import", deep?: boolean): MImportNode[]
  • findChildTagsByTagName(tagName: "m-if", deep?: boolean): MIfNode[]
  • findChildTagsByTagName(tagName: "m-for", deep?: boolean): MForNode[]
  • findChildTagsByTagName(tagName: "m-data", deep?: boolean): MDataNode[]
  • findChildTagsByTagName(tagName: "style", deep?: boolean): StyleNode[]
  • findChildTagsByTagName(tagName: "script", deep?: boolean): ScriptNode[]
  • findChildTagsByTagName(tagName: "a", deep?: boolean): AnchorNode[]
  • findChildTagsByTagName(tagName: "m-whitespace", deep?: boolean): MWhitespaceNode[]
  • findChildTagsByTagName(tagName: string, deep?: boolean): TagNode[]

findNext

  • findNext(matcher: (node: Node) => boolean, deep?: boolean): null | Node
  • Finds the next node that matches a callback. The next node is defined as the first matching child, sibling, or sibling's child node starting from this node. This only checks child and sibling nodes, it will not move further up the DOM tree. To check only sibling nodes, set node to false.

    Parameters

    • matcher: (node: Node) => boolean

      Callback to test nodes

        • (node: Node): boolean
        • Parameters

          Returns boolean

    • deep: boolean = true

      If true or not specified, then child nodes will be checked

    Returns null | Node

    The first matching node, or null if none found.

getChildTags

  • Gets all child TagNodes from this parent

    Returns TagNode[]

    array of TagNodes containing all child tags

prependChild

  • prependChild(child: Node): void
  • Inserts a child at the start of this parent's children

    Parameters

    • child: Node

      Node to insert

    Returns void

prependChildren

  • prependChildren(children: Node[]): void
  • Prepend multiple children to the start of this parent's child list

    Parameters

    • children: Node[]

      Child nodes to prepend. Can be empty.

    Returns void

prependSibling

  • prependSibling(node: Node): void

removeSelf

  • removeSelf(keepChildren?: boolean): void
  • Removes this node from the DOM, but optionally preserves children. If keepChildren is true, then child nodes will be reattached to the DOM in place of this node. Effectively "promotes" child nodes.

    Parameters

    • keepChildren: boolean = false

      If true, child nodes will be kept.

    Returns void

replaceSelf

  • replaceSelf(nodes: Node[]): void
  • Remove this node and all children from the DOM, and insert one or more nodes in its place

    Parameters

    • nodes: Node[]

      Nodes to insert in replacement. Can be empty.

    Returns void

toHtml

  • toHtml(): string
  • Serializes this node into HTML. Child nodes will be automatically serialize.

    Returns string

    HTML text representation of this node

Static isNodeWithChildren

Generated using TypeDoc