SelectorList Class

A selector list (https://drafts.csswg.org/selectors-4/#selector-list). Parsed selectors are immutable.

public sealed class SelectorList

Properties

NameDescription
MaxSpecificityThe maximum specificity of the selectors of the list (used by :is(), :not(), :has() and :nth-child(of S)).
SelectorsGets the complex selectors of the list, in source order.

MaxSpecificity

Selector.cs

The maximum specificity of the selectors of the list (used by :is(), :not(), :has() and :nth-child(of S)).

public Specificity MaxSpecificity { get; }

Property value

Specificity

Selectors

Selector.cs

Gets the complex selectors of the list, in source order.

public ImmutableArray<ComplexSelector> Selectors { get; }

Methods

NameDescription
Matches(Element)Returns whether the element matches the selector, as Element.Matches does (https://dom.spec.whatwg.org/#dom-element-matches).
Parse(string)Parses a selector list, as querySelector does (https://dom.spec.whatwg.org/#scope-match-a-selectors-string): namespace prefixes other than * and the empty prefix are invalid.
ToString()Serializes the selector list (https://drafts.csswg.org/cssom/#serialize-a-group-of-selectors).
TryParse(string, SelectorList?)Parses a selector list, as SelectorList.Parse does, without throwing when the selector is invalid.

Matches(Element)

Selector.cs

Returns whether the element matches the selector, as Element.Matches does (https://dom.spec.whatwg.org/#dom-element-matches).

public bool Matches(Element element)

Parameters

element Element

Returns

bool

Parse(string)

Selector.cs

Parses a selector list, as querySelector does (https://dom.spec.whatwg.org/#scope-match-a-selectors-string): namespace prefixes other than * and the empty prefix are invalid.

public static SelectorList Parse(string selectors)

Parameters

selectors string

Returns

SelectorList

Exceptions

DomException
The selector is invalid ("SyntaxError").

ToString()

Selector.cs

Serializes the selector list (https://drafts.csswg.org/cssom/#serialize-a-group-of-selectors).

public override string ToString()

Returns

string

TryParse(string, SelectorList?)

Selector.cs

Parses a selector list, as SelectorList.Parse does, without throwing when the selector is invalid.

public static bool TryParse(string selectors, out SelectorList? result)

Parameters

selectors string
result SelectorList?

Returns

bool