Table of Contents

Class Node

Namespace
CSharpToJavaScript.APIs.JS
Assembly
CSharpToJavaScript.dll

In addition, every kind of DOM node is represented by an interface based on
Node. These include Attr, CharacterData
(which Text, Comment, CDATASection and
ProcessingInstruction are all based on), and DocumentType.

[Value("Node")]
public class Node : EventTarget
Inheritance
Node
Derived
Inherited Members

Remarks

In some cases, a particular feature of the base Node interface may not
apply to one of its child interfaces; in that case, the inheriting node may
return null or throw an exception, depending on circumstances. For example,
attempting to add children to a node type that cannot have children will throw an
exception.

See also on MDN

Constructors

Node()

public Node()

Fields

ATTRIBUTE_NODE

[Value("ATTRIBUTE_NODE")]
public const ushort ATTRIBUTE_NODE = 2

Field Value

ushort

CDATA_SECTION_NODE

[Value("CDATA_SECTION_NODE")]
public const ushort CDATA_SECTION_NODE = 4

Field Value

ushort

COMMENT_NODE

[Value("COMMENT_NODE")]
public const ushort COMMENT_NODE = 8

Field Value

ushort

DOCUMENT_FRAGMENT_NODE

[Value("DOCUMENT_FRAGMENT_NODE")]
public const ushort DOCUMENT_FRAGMENT_NODE = 11

Field Value

ushort

DOCUMENT_NODE

[Value("DOCUMENT_NODE")]
public const ushort DOCUMENT_NODE = 9

Field Value

ushort

DOCUMENT_POSITION_CONTAINED_BY

[Value("DOCUMENT_POSITION_CONTAINED_BY")]
public const ushort DOCUMENT_POSITION_CONTAINED_BY = 16

Field Value

ushort

DOCUMENT_POSITION_CONTAINS

[Value("DOCUMENT_POSITION_CONTAINS")]
public const ushort DOCUMENT_POSITION_CONTAINS = 8

Field Value

ushort

DOCUMENT_POSITION_DISCONNECTED

[Value("DOCUMENT_POSITION_DISCONNECTED")]
public const ushort DOCUMENT_POSITION_DISCONNECTED = 1

Field Value

ushort

DOCUMENT_POSITION_FOLLOWING

[Value("DOCUMENT_POSITION_FOLLOWING")]
public const ushort DOCUMENT_POSITION_FOLLOWING = 4

Field Value

ushort

DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC

[Value("DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC")]
public const ushort DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC = 32

Field Value

ushort

DOCUMENT_POSITION_PRECEDING

[Value("DOCUMENT_POSITION_PRECEDING")]
public const ushort DOCUMENT_POSITION_PRECEDING = 2

Field Value

ushort

DOCUMENT_TYPE_NODE

[Value("DOCUMENT_TYPE_NODE")]
public const ushort DOCUMENT_TYPE_NODE = 10

Field Value

ushort

ELEMENT_NODE

[Value("ELEMENT_NODE")]
public const ushort ELEMENT_NODE = 1

Field Value

ushort

ENTITY_NODE

[Value("ENTITY_NODE")]
public const ushort ENTITY_NODE = 6

Field Value

ushort

ENTITY_REFERENCE_NODE

[Value("ENTITY_REFERENCE_NODE")]
public const ushort ENTITY_REFERENCE_NODE = 5

Field Value

ushort

NOTATION_NODE

[Value("NOTATION_NODE")]
public const ushort NOTATION_NODE = 12

Field Value

ushort

PROCESSING_INSTRUCTION_NODE

[Value("PROCESSING_INSTRUCTION_NODE")]
public const ushort PROCESSING_INSTRUCTION_NODE = 7

Field Value

ushort

TEXT_NODE

[Value("TEXT_NODE")]
public const ushort TEXT_NODE = 3

Field Value

ushort

Properties

BaseURI

The read-only baseURI property of the Node interface
returns the absolute base URL of the document containing the node.

[Value("baseURI")]
public string BaseURI { get; }

Property Value

string

A string representing the base URL of the Node.

Remarks

The base URL is used to resolve relative URLs when the browser needs to obtain an absolute URL, for example when processing the HTML img element's src attribute or the xlink:href {{deprecated_inline}} or href attributes in SVG.

Although this property is read-only, its value is determined by an algorithm each time
the property is accessed, and may change if the conditions changed.

The base URL is determined as follows:

-base element.

See also on MDN

ChildNodes

The read-only childNodes property of the Node interface returns a live
NodeList of child Node of the given element where
the first child node is assigned index 0. Child nodes include elements, text and
comments.

[Value("childNodes")]
public NodeList ChildNodes { get; }

Property Value

NodeList

A live NodeList containing the children of the node.

NOTE
Several calls to childNodes return the same NodeList.

Remarks

NOTE

The NodeList being live means that its content is changed each time
new children are added or removed.

Browsers insert text nodes into a document to represent whitespace in the source markup.
Therefore a node obtained, for example, using Node.childNodes[0]
may refer to a whitespace text node rather than the actual element the author intended to get.

See Working with whitespace in the DOM for more information.

The items in the collection of nodes are objects, not strings. To get data from node
objects, use their properties. For example, to get the name of the first
childNode, you can use elementNodeReference.childNodes[0].nodeName.

The Document object itself has two children: the Doctype declaration and the
root element, typically referred to as documentElement. In HTML
documents the latter is the html element.

It is important to keep in mind that childNodes includes all child nodes,
including non-element nodes like text and comment.
To get a collection containing only elements, use Element.Children instead.

-FirstChild
-LastChild
-NextSibling
-PreviousSibling
-Element.Children

See also on MDN

FirstChild

The read-only firstChild property of the Node interface
returns the node's first child in the tree,
or null if the node has no children.

[Value("firstChild")]
public Node? FirstChild { get; }

Property Value

Node

A Node, or null if there are none.

Remarks

If the node is a Document,
this property returns the first node in the list of its direct children.

NOTE

This property returns any type of node that is the first child of this one.
It may be a Text or a Comment node.
If you want to get the first Element that is a child of another element,
consider using Element.FirstElementChild.

-Element.FirstElementChild
-LastChild

See also on MDN

IsConnected

The read-only isConnected property of the Node interface
returns a boolean indicating whether the node is connected
(directly or indirectly) to a Document object.

[Value("isConnected")]
public bool IsConnected { get; }

Property Value

bool

A boolean value that is true if the node is connected to its relevant context object,
and false if not.

Remarks

LastChild

The read-only lastChild property of the Node interface
returns the last child of the node, or null if there are no child nodes.

[Value("lastChild")]
public Node? LastChild { get; }

Property Value

Node

A Node that is the last child of the node, or null if there are no child nodes.

Remarks

NOTE

This property returns any type of node that is the last child of this one.
It may be a Text or a Comment node.
If you want to get the last Element that is a child of another element,
consider using Element.LastElementChild.

-FirstChild
-Element.LastElementChild

See also on MDN

NextSibling

The read-only nextSibling property of the Node interface
returns the node immediately following the specified one in their
parent's ChildNodes, or returns null
if the specified node is the last child in the parent element.

[Value("nextSibling")]
public Node? NextSibling { get; }

Property Value

Node

A Node representing the next sibling of the current node,
or null if there are none.

Remarks

NOTE

Browsers insert Text nodes into a document to represent whitespace in the source markup.
Therefore a node obtained, for example, using Node.firstChild
or Node.previousSibling
may refer to a whitespace text node rather than the actual element the author
intended to get.

The section Working with whitespace in the DOM
contains more information about this behavior.

You can use Element.NextElementSibling to obtain the next element
skipping any whitespace nodes, other between-element text, or comments.

To navigate the opposite way through the child nodes list use Node.previousSibling.

-Element.NextElementSibling
-PreviousSibling

See also on MDN

NodeName

The read-only nodeName property of Node returns the name of the current node as a string.

[Value("nodeName")]
public string NodeName { get; }

Property Value

string

A string. Values for the different types of nodes are:

Remarks

NodeType

The read-only nodeType property of a Node interface is an integer
that identifies what the node is. It distinguishes different kind of nodes from each other,
such as Element, Text and Comment.

[Value("nodeType")]
public ushort NodeType { get; }

Property Value

ushort

An integer which specifies the type of the node. Possible values are:The following constants have been deprecated and are not in use anymore: Node.ENTITY_REFERENCE_NODE (5),
Node.ENTITY_NODE (6), and Node.NOTATION_NODE (12).

Remarks

NodeValue

The nodeValue property of the Node interface returns or sets the value of the current node.

[Value("nodeValue")]
public string? NodeValue { get; set; }

Property Value

string

A string containing the value of the current node, if any.
For the document itself, nodeValue returns null.
For text, comment, and CDATA nodes, nodeValue returns the content of the node.
For attribute nodes, the value of the attribute is returned.The following table shows the return values for different types of nodes.

NodeValue of nodeValue
CDATASectionContent of the CDATA section
CommentContent of the comment
Documentnull
DocumentFragmentnull
DocumentTypenull
Elementnull
NamedNodeMapnull
ProcessingInstructionEntire content excluding the target
TextContent of the text node
NOTE
When nodeValue is defined to be null, setting it has no effect.

Remarks

OwnerDocument

The read-only ownerDocument property of the Node interface
returns the top-level document object of the node.

[Value("ownerDocument")]
public Document? OwnerDocument { get; }

Property Value

Document

A Document that is the top-level object in which all the
child nodes are created.If this property is used on a node that is itself a document, the value is null.

Remarks

ParentElement

The read-only parentElement property of Node interface
returns the DOM node's parent Element, or null if the node either has no
parent, or its parent isn't a DOM Element. ParentNode on the other hand returns any kind of parent, regardless of its type.

[Value("parentElement")]
public Element? ParentElement { get; }

Property Value

Element

An Element that is the parent element of the current node,
or null if there isn't one.

Remarks

ParentNode

The read-only parentNode property of the Node interface
returns the parent of the specified node in the DOM tree.

[Value("parentNode")]
public Node? ParentNode { get; }

Property Value

Node

A Node that is the parent of the current node. The parent of an element is
an Element node, a Document node, or a DocumentFragment node.

Remarks

Document and DocumentFragment nodes can never have a parent, so
parentNode will always return null.
It also returns null if the node has just been created
and is not yet attached to the tree. ParentElement on the other hand only returns Element nodes.

-FirstChild
-LastChild
-ChildNodes
-NextSibling
-ParentElement
-PreviousSibling
-RemoveChild(Node)

See also on MDN

PreviousSibling

The read-only previousSibling property of the Node interface
returns the node immediately preceding the specified one in its parent's
ChildNodes list,
or null if the specified node is the first in that list.

[Value("previousSibling")]
public Node? PreviousSibling { get; }

Property Value

Node

A Node representing the previous sibling of the current node,
or null if there are none.

Remarks

NOTE

Browsers insert text nodes into a document to represent whitespace in the source markup.
Therefore a node obtained, for example, using Node.firstChild
or Node.previousSibling
may refer to a whitespace text node rather than the actual element the author intended to get.

See Working with whitespace in the DOM for more information.

You can use previousElementSibling
to get the previous element node (skipping text nodes and any other non-element nodes).

To navigate the opposite way through the child nodes list use Node.nextSibling.

-NextSibling
-Element.PreviousElementSibling

See also on MDN

TextContent

The textContent property of the Node
interface represents the text content of the node and its descendants.

[Value("textContent")]
public string? TextContent { get; set; }

Property Value

string

A string, or null. Its value depends on the situation:

WARNING
Setting textContent on a node removes all of the node's children
and replaces them with a single text node with the given string value.

Remarks

NOTE

textContent and InnerText are easily confused,
but the two properties are different in important ways.

-InnerText
-InnerHTML

See also on MDN

Methods

AppendChild(Node)

The appendChild() method of the Node interface adds a node to the end of the list of children of a specified parent node.

[Value("appendChild")]
public Node AppendChild(Node node)

Parameters

node Node

Returns

Node

A Node that is the appended child (child), except when child is a DocumentFragment, in which case the empty DocumentFragment is returned.

Remarks

NOTE

If the given child is a reference to an existing node in the document, appendChild() moves it from its current position to the new position.

If the given child is a DocumentFragment, the entire contents of the DocumentFragment are moved into the child list of the specified parent node.

appendChild() returns the newly appended node, or if the child is a DocumentFragment, the emptied fragment.

NOTE

Unlike this method, the Element.Append method supports multiple arguments and appending strings. You can prefer using it if your node is an element.

-RemoveChild(Node)
-ReplaceChild(Node, Node)
-InsertBefore(Node, Node?)
-HasChildNodes()
-InsertAdjacentElement(string, Element)
-Element.Append

See also on MDN

CloneNode(bool)

The cloneNode() method of the Node interface
returns a duplicate of the node on which this method was called.
Its parameter controls if the subtree contained in a node is also cloned or not.

[Value("cloneNode")]
public Node CloneNode(bool subtree = false)

Parameters

subtree bool

Returns

Node

The new Node cloned.
The cloned node has no parent and is not part of the document,
until it is added to another node that is part of the document,
using AppendChild(Node) or a similar method.

Remarks

Cloning a node copies all of its attributes and their values,
including intrinsic (inline) listeners. It does not copy event listeners added
using addEventListener() or
those assigned to element properties (e.g., node.onclick = someFunction).
Additionally, for a canvas element, the painted image is not copied.

WARNING

cloneNode() may lead to duplicate element IDs in a document!

If the original node has an id attribute, and the clone
will be placed in the same document, then you should modify the clone's ID to be
unique.

Also, name attributes may need to be modified,
depending on whether duplicate names are expected.

To clone a node to insert into a different document, use
ImportNode(Node, bool) instead.

See also on MDN

CompareDocumentPosition(Node)

The compareDocumentPosition() method of the Node interface
reports the position of its argument node relative to the node on which it is called.

[Value("compareDocumentPosition")]
public ushort CompareDocumentPosition(Node other)

Parameters

other Node

Returns

ushort

An integer value representing otherNode's position relative to node
as a bitmask combining the
following constant properties of Node:Zero or more bits can be set, depending on which scenarios apply. For example, if
otherNode is located earlier in the document and
contains the node on which compareDocumentPosition() was
called, then both the DOCUMENT_POSITION_CONTAINS and
DOCUMENT_POSITION_PRECEDING bits would be set, producing a value of 10 (0x0A).

Remarks

Contains(Node?)

The contains() method of the Node interface
returns a boolean value indicating
whether a node is a descendant of a given node, that is the node itself,
one of its direct children (ChildNodes),
one of the children's direct children, and so on.

[Value("contains")]
public bool Contains(Node? other)

Parameters

other Node

Returns

bool

A boolean value that is true if otherNode is contained in the node,
false if not.If the otherNode parameter is null,
contains() always returns false.

Remarks

NOTE

A node is contained inside itself.

-CompareDocumentPosition(Node)
-HasChildNodes()

See also on MDN

GetRootNode(GetRootNodeOptions)

The getRootNode() method of the Node interface
returns the context object's root,
which optionally includes the shadow root if it is available.

[Value("getRootNode")]
public Node GetRootNode(GetRootNodeOptions options = null)

Parameters

options GetRootNodeOptions

Returns

Node

An object inheriting from 'Node'. This will differ in exact form depending
on where you call getRootNode(); for example:

Remarks

HasChildNodes()

The hasChildNodes() method of the Node interface
returns a boolean value indicating
whether the given Node has child nodes or not.

[Value("hasChildNodes")]
public bool HasChildNodes()

Returns

bool

A boolean value that is true if the node has child nodes, and
false otherwise.

Remarks

InsertBefore(Node, Node?)

The insertBefore() method of the Node interface
inserts a node before a reference node as a child of a specified parent node.

[Value("insertBefore")]
public Node InsertBefore(Node node, Node? child)

Parameters

node Node
child Node

Returns

Node

Returns the added child (unless newNode is a DocumentFragment,
in which case the empty DocumentFragment is returned).

Remarks

If the given node already exists in the document,
insertBefore() moves it from its current position to the new position.
(That is, it will automatically be removed from its existing parent
before appending it to the specified new parent.)

This means that a node cannot be in two locations of the document simultaneously.

NOTE

The CloneNode(bool) can be used to make a copy
of the node before appending it under the new parent. Note that the copies made with
cloneNode() will not be automatically kept in sync.

If the given child is a DocumentFragment, the entire contents of the
DocumentFragment are moved into the child list of the specified parent
node.

-RemoveChild(Node)
-ReplaceChild(Node, Node)
-AppendChild(Node)
-HasChildNodes()
-InsertAdjacentElement(string, Element)
-Element.Prepend
-Element.Before
-Element.After

See also on MDN

IsDefaultNamespace(string?)

The isDefaultNamespace() method of the Node interface accepts a namespace URI as an argument.
It returns a boolean value that is true if the namespace is the default namespace on the given node and false if not.

[Value("isDefaultNamespace")]
public bool IsDefaultNamespace(string? namespace_)

Parameters

namespace_ string

Returns

bool

A boolean value that holds the return value true or false, indicating if the parameter is the default namespace, or not.

Remarks

NOTE

The default namespace of an HTML element is always "". For a SVG element, it is set by the xmlns attribute.

-LookupNamespaceURI(string?)
-LookupPrefix(string?)

See also on MDN

IsEqualNode(Node?)

The isEqualNode() method of the Node interface tests whether two nodes are equal.
Two nodes are equal when they have the same type, defining characteristics (for
elements, this would be their ID, number of children, and so forth), its attributes
match, and so on. The specific set of data points that must match varies depending on
the types of the nodes.

[Value("isEqualNode")]
public bool IsEqualNode(Node? otherNode)

Parameters

otherNode Node

Returns

bool

A boolean value that is true if the two nodes are equals, or false if not.
If otherNode is null, isEqualNode() always return false.

Remarks

IsSameNode(Node?)

The isSameNode() method of the Node interface
is a legacy alias the for the === strict equality operator.
That is, it tests whether two nodes are the same
(in other words, whether they reference the same object).

[Value("isSameNode")]
public bool IsSameNode(Node? otherNode)

Parameters

otherNode Node

Returns

bool

A boolean value that is true if both nodes are strictly equal, false if not.

Remarks

NOTE

There is no need to use isSameNode(); instead use the === strict equality operator.

-IsEqualNode(Node?)

See also on MDN

LookupNamespaceURI(string?)

The lookupNamespaceURI() method of the Node interface
takes a prefix as parameter and returns the namespace URI associated with it on the given node if found (and
null if not). This method's existence allows Node objects to be passed as a namespace resolver to XPathEvaluator.CreateExpression and XPathEvaluator.Evaluate.

[Value("lookupNamespaceURI")]
public string? LookupNamespaceURI(string? prefix)

Parameters

prefix string

Returns

string

A string containing the namespace URI corresponding to the prefix.

Remarks

LookupPrefix(string?)

The lookupPrefix() method of the Node interface
returns a string containing the prefix for a given namespace URI, if present,
and null if not.
When multiple prefixes are possible, the first prefix is returned.

[Value("lookupPrefix")]
public string? LookupPrefix(string? namespace_)

Parameters

namespace_ string

Returns

string

A string containing the corresponding prefix, or null if none has been found.
If namespace is null, or the empty string, lookupPrefix() returns null.If the node is a DocumentType or a DocumentFragment,
lookupPrefix() always returns null.

Remarks

Normalize()

The normalize() method of the Node interface puts the specified node
and all of its sub-tree into a normalized form.
In a normalized sub-tree, no text nodes in the sub-tree are empty and there are no adjacent text nodes.

[Value("normalize")]
public GlobalObject.Undefined Normalize()

Returns

GlobalObject.Undefined

None.

Remarks

RemoveChild(Node)

The removeChild() method of the Node interface
removes a child node from the DOM and returns the removed node.

[Value("removeChild")]
public Node RemoveChild(Node child)

Parameters

child Node

Returns

Node

The removed child node.

Remarks

NOTE

As long as a reference is kept on the removed child,
it still exists in memory, but is no longer part of the DOM.
It can still be reused later in the code.

If the return value of removeChild() is not stored, and no other reference is kept,
it will be automatically deleted from memory after a short time.

Unlike CloneNode(bool) the return value preserves the EventListener objects associated with it.

-ReplaceChild(Node, Node)
-ParentNode
-Element.Remove
-CloneNode(bool)

See also on MDN

ReplaceChild(Node, Node)

The replaceChild() method of the Node interface replaces a child node within the given (parent) node.

[Value("replaceChild")]
public Node ReplaceChild(Node node, Node child)

Parameters

node Node
child Node

Returns

Node

The replaced Node. This is the same node as oldChild.

Remarks