Range Class

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

public sealed class Range : AbstractRange
Inheritance
AbstractRange Range

Constructors

NameDescription
Range()Creates a collapsed range at the start of the current global document.

Range()

Range.cs

Creates a collapsed range at the start of the current global document.

public Range()

Properties

NameDescription
CommonAncestorContainerhttps://dom.spec.whatwg.org/#dom-range-commonancestorcontainer

CommonAncestorContainer

Range.cs

https://dom.spec.whatwg.org/#dom-range-commonancestorcontainer

public Node CommonAncestorContainer { get; }

Methods

NameDescription
CloneContents()Returns a document fragment containing a copy of the contents of the range.
CloneRange()Returns a new range with the same boundary points as this range.
Collapse(bool)Collapses the range to its start when toStart is true, or to its end otherwise.
CompareBoundaryPoints(ushort, Range)https://dom.spec.whatwg.org/#dom-range-compareboundarypoints
ComparePoint(Node, uint)https://dom.spec.whatwg.org/#dom-range-comparepoint
CreateContextualFragment(TrustedHtml)https://html.spec.whatwg.org/multipage/dynamic-markup-insertion.html#dom-range-createcontextualfragment
CreateContextualFragment(string)https://html.spec.whatwg.org/multipage/dynamic-markup-insertion.html#dom-range-createcontextualfragment
DeleteContents()https://dom.spec.whatwg.org/#dom-range-deletecontents
Detach()Does nothing (https://dom.spec.whatwg.org/#dom-range-detach).
ExtractContents()Removes the contents of the range from the tree and returns them in a document fragment.
GetBoundingClientRect()Returns the bounding box of the boxes of the range (https://drafts.csswg.org/cssom-view/#dom-range-getboundingclientrect): see Range.GetClientRects and Element.GetBoundingClientRect.
GetClientRects()Returns the boxes of the range (https://drafts.csswg.org/cssom-view/#dom-range-getclientrects), in the coordinates of the viewport: the boxes of the elements contained in the range whose parent is not (see Element.GetClientRects), and for each text node selected or partially selected, the rectangle of the selected characters of each of its text fragments (their advance along the inline axis, the ascent and descent of the font along the block axis; a collapsed range in a text gives a rectangle without width), with the transforms applied.
InsertNode(Node)Inserts the given node into the tree at the start of the range.
IntersectsNode(Node)https://dom.spec.whatwg.org/#dom-range-intersectsnode
IsPointInRange(Node, uint)https://dom.spec.whatwg.org/#dom-range-ispointinrange
SelectNode(Node)https://dom.spec.whatwg.org/#concept-range-select
SelectNodeContents(Node)Sets the range to contain all the children of the given node.
SetEnd(Node, uint)Sets the end of the range to the given node and offset.
SetEndAfter(Node)Sets the end of the range to the position just after the given node.
SetEndBefore(Node)Sets the end of the range to the position just before the given node.
SetStart(Node, uint)Sets the start of the range to the given node and offset.
SetStartAfter(Node)Sets the start of the range to the position just after the given node.
SetStartBefore(Node)Sets the start of the range to the position just before the given node.
SurroundContents(Node)https://dom.spec.whatwg.org/#dom-range-surroundcontents
ToString()The stringification behavior (https://dom.spec.whatwg.org/#dom-range-stringifier).

CloneContents()

Range.cs

Returns a document fragment containing a copy of the contents of the range.

public DocumentFragment CloneContents()

CloneRange()

Range.cs

Returns a new range with the same boundary points as this range.

public Range CloneRange()

Collapse(bool)

Range.cs

Collapses the range to its start when toStart is true, or to its end otherwise.

public void Collapse(bool toStart = false)

CompareBoundaryPoints(ushort, Range)

Range.cs

https://dom.spec.whatwg.org/#dom-range-compareboundarypoints

public short CompareBoundaryPoints(ushort how, Range sourceRange)

ComparePoint(Node, uint)

Range.cs

https://dom.spec.whatwg.org/#dom-range-comparepoint

public short ComparePoint(Node node, uint offset)

CreateContextualFragment overloads

CreateContextualFragment(TrustedHtml)

DynamicMarkup.cs

https://html.spec.whatwg.org/multipage/dynamic-markup-insertion.html#dom-range-createcontextualfragment

public DocumentFragment CreateContextualFragment(TrustedHtml fragment)

CreateContextualFragment(string)

DynamicMarkup.cs

https://html.spec.whatwg.org/multipage/dynamic-markup-insertion.html#dom-range-createcontextualfragment

public DocumentFragment CreateContextualFragment(string fragment)
Parameters
fragment string
Returns

DocumentFragment

Exceptions
TypeErrorException
Trusted Types are enforced and the default policy did not convert the value.
See also

DeleteContents()

Range.cs

https://dom.spec.whatwg.org/#dom-range-deletecontents

public void DeleteContents()

Detach()

Range.cs

Does nothing (https://dom.spec.whatwg.org/#dom-range-detach).

public void Detach()

ExtractContents()

Range.cs

Removes the contents of the range from the tree and returns them in a document fragment.

public DocumentFragment ExtractContents()

GetBoundingClientRect()

CssomView.cs

Returns the bounding box of the boxes of the range (https://drafts.csswg.org/cssom-view/#dom-range-getboundingclientrect): see Range.GetClientRects and Element.GetBoundingClientRect.

public DomRect GetBoundingClientRect()

GetClientRects()

CssomView.cs

Returns the boxes of the range (https://drafts.csswg.org/cssom-view/#dom-range-getclientrects), in the coordinates of the viewport: the boxes of the elements contained in the range whose parent is not (see Element.GetClientRects), and for each text node selected or partially selected, the rectangle of the selected characters of each of its text fragments (their advance along the inline axis, the ascent and descent of the font along the block axis; a collapsed range in a text gives a rectangle without width), with the transforms applied.

public DomRectList GetClientRects()

InsertNode(Node)

Range.cs

Inserts the given node into the tree at the start of the range.

public void InsertNode(Node node)

IntersectsNode(Node)

Range.cs

https://dom.spec.whatwg.org/#dom-range-intersectsnode

public bool IntersectsNode(Node node)

IsPointInRange(Node, uint)

Range.cs

https://dom.spec.whatwg.org/#dom-range-ispointinrange

public bool IsPointInRange(Node node, uint offset)

SelectNode(Node)

Range.cs

https://dom.spec.whatwg.org/#concept-range-select

public void SelectNode(Node node)

SelectNodeContents(Node)

Range.cs

Sets the range to contain all the children of the given node.

public void SelectNodeContents(Node node)

SetEnd(Node, uint)

Range.cs

Sets the end of the range to the given node and offset.

public void SetEnd(Node node, uint offset)

SetEndAfter(Node)

Range.cs

Sets the end of the range to the position just after the given node.

public void SetEndAfter(Node node)

SetEndBefore(Node)

Range.cs

Sets the end of the range to the position just before the given node.

public void SetEndBefore(Node node)

SetStart(Node, uint)

Range.cs

Sets the start of the range to the given node and offset.

public void SetStart(Node node, uint offset)

SetStartAfter(Node)

Range.cs

Sets the start of the range to the position just after the given node.

public void SetStartAfter(Node node)

SetStartBefore(Node)

Range.cs

Sets the start of the range to the position just before the given node.

public void SetStartBefore(Node node)

SurroundContents(Node)

Range.cs

https://dom.spec.whatwg.org/#dom-range-surroundcontents

public void SurroundContents(Node newParent)

ToString()

Range.cs

The stringification behavior (https://dom.spec.whatwg.org/#dom-range-stringifier).

public override string ToString()

Returns

string

Constants

NameDescription
EndToEndCompares the end of the given range to the end of this range.
EndToStartCompares the start of the given range to the end of this range.
StartToEndCompares the end of the given range to the start of this range.
StartToStartCompares the start of the given range to the start of this range.

EndToEnd

Compares the end of the given range to the end of this range.

public const ushort EndToEnd = 2

EndToStart

Compares the start of the given range to the end of this range.

public const ushort EndToStart = 3

StartToEnd

Compares the end of the given range to the start of this range.

public const ushort StartToEnd = 1

StartToStart

Compares the start of the given range to the start of this range.

public const ushort StartToStart = 0