DocumentFragment Class

https://dom.spec.whatwg.org/#interface-documentfragment

public class DocumentFragment : Node, INonElementParentNode, IParentNode
Inheritance
Node DocumentFragment
Implements

Constructors

NameDescription
DocumentFragment()Creates an empty document fragment owned by the current global document.

DocumentFragment()

DocumentFragment.cs

Creates an empty document fragment owned by the current global document.

public DocumentFragment()

Properties

NameDescription
ChildElementCountGets the number of child elements.
ChildrenGets the live collection of the child elements.
FirstElementChildGets the first child that is an element, or null when there is none.
LastElementChildGets the last child that is an element, or null when there is none.
NodeNameGets the node name of a document fragment, which is #document-fragment.
NodeTypeGets the node type of a document fragment, which is 11 (DOCUMENT_FRAGMENT_NODE).
TextContentGets or sets the concatenation of the text of the descendant text nodes; setting it replaces all the children.

ChildElementCount

Mixins.Members.cs

Gets the number of child elements.

public uint ChildElementCount { get; }

Gets the live collection of the child elements.

public HtmlCollection Children { get; }

FirstElementChild

Mixins.Members.cs

Gets the first child that is an element, or null when there is none.

public Element? FirstElementChild { get; }

LastElementChild

Mixins.Members.cs

Gets the last child that is an element, or null when there is none.

public Element? LastElementChild { get; }

Gets the node name of a document fragment, which is #document-fragment.

public override string NodeName { get; }

Property value

string

Gets the node type of a document fragment, which is 11 (DOCUMENT_FRAGMENT_NODE).

public override ushort NodeType { get; }

Property value

ushort

Gets or sets the concatenation of the text of the descendant text nodes; setting it replaces all the children.

public override string? TextContent { get; set; }

Property value

string?

Methods

NameDescription
Append(ReadOnlySpan<NodeOrString>)Inserts the nodes after the last child, converting the strings into text nodes.
GetElementById(string)Returns the first descendant element, in tree order, whose ID is the given value, or null.
MoveBefore(Node, Node?)Moves the node, preserving its state, before the given child (or to the end when the child is null).
Prepend(ReadOnlySpan<NodeOrString>)Inserts the nodes before the first child, converting the strings into text nodes.
QuerySelector(SelectorList)Returns the first descendant element, in tree order, that matches the parsed selector list, or null.
QuerySelector(string)Returns the first descendant element, in tree order, that matches the selectors, or null.
QuerySelector<T>(SelectorList)Returns the first descendant, in tree order, that is a T and matches the parsed selector.
QuerySelector<T>(string)Returns the first descendant, in tree order, that is a T and matches the selector.
QuerySelectorAll(SelectorList)Returns the descendant elements, in tree order, that match the parsed selector list.
QuerySelectorAll(string)Returns the descendant elements, in tree order, that match the selectors.
QuerySelectorAll<T>(SelectorList)Returns the descendants, in tree order, that are a T and match the parsed selector.
QuerySelectorAll<T>(string)Returns the descendants, in tree order, that are a T and match the selector.
ReplaceChildren(ReadOnlySpan<NodeOrString>)Replaces all the children with the given nodes, converting the strings into text nodes.

Append(ReadOnlySpan<NodeOrString>)

Mixins.Members.cs

Inserts the nodes after the last child, converting the strings into text nodes.

public void Append(params scoped ReadOnlySpan<NodeOrString> nodes)

GetElementById(string)

Mixins.Members.cs

Returns the first descendant element, in tree order, whose ID is the given value, or null.

public Element? GetElementById(string elementId)

MoveBefore(Node, Node?)

Mixins.Members.cs

Moves the node, preserving its state, before the given child (or to the end when the child is null).

public void MoveBefore(Node node, Node? child)

Prepend(ReadOnlySpan<NodeOrString>)

Mixins.Members.cs

Inserts the nodes before the first child, converting the strings into text nodes.

public void Prepend(params scoped ReadOnlySpan<NodeOrString> nodes)

QuerySelector overloads

QuerySelector(SelectorList)

Mixins.Members.cs

Returns the first descendant element, in tree order, that matches the parsed selector list, or null.

public Element? QuerySelector(SelectorList selectors)
Parameters
selectors SelectorList
Returns

Element?

QuerySelector(string)

Mixins.Members.cs

Returns the first descendant element, in tree order, that matches the selectors, or null.

public Element? QuerySelector(string selectors)

QuerySelector<T>(SelectorList)

Mixins.Members.cs

Returns the first descendant, in tree order, that is a T and matches the parsed selector.

public T? QuerySelector<T>(SelectorList selectors) where T : Element
Type parameters
T
Parameters
selectors SelectorList
Returns

T?

QuerySelector<T>(string)

Mixins.Members.cs

Returns the first descendant, in tree order, that is a T and matches the selector.

public T? QuerySelector<T>(string selectors) where T : Element
Type parameters
T
Parameters
selectors string
Returns

T?

QuerySelectorAll overloads

QuerySelectorAll(SelectorList)

Mixins.Members.cs

Returns the descendant elements, in tree order, that match the parsed selector list.

public NodeList QuerySelectorAll(SelectorList selectors)
Parameters
selectors SelectorList
Returns

NodeList

QuerySelectorAll(string)

Mixins.Members.cs

Returns the descendant elements, in tree order, that match the selectors.

public NodeList QuerySelectorAll(string selectors)

QuerySelectorAll<T>(SelectorList)

Mixins.Members.cs

Returns the descendants, in tree order, that are a T and match the parsed selector.

public IReadOnlyList<T> QuerySelectorAll<T>(SelectorList selectors) where T : Element
Type parameters
T
Parameters
selectors SelectorList
Returns

IReadOnlyList<T>

QuerySelectorAll<T>(string)

Mixins.Members.cs

Returns the descendants, in tree order, that are a T and match the selector.

public IReadOnlyList<T> QuerySelectorAll<T>(string selectors) where T : Element
Type parameters
T
Parameters
selectors string
Returns

IReadOnlyList<T>

ReplaceChildren(ReadOnlySpan<NodeOrString>)

Mixins.Members.cs

Replaces all the children with the given nodes, converting the strings into text nodes.

public void ReplaceChildren(params scoped ReadOnlySpan<NodeOrString> nodes)