/// <summary> /// Returns a list of the elements within the document (using depth-first pre-order traversal /// of the document's nodes) that match the specified group of selectors. /// Requires either a non-empty nodelist or a valid scope node. /// </summary> /// <param name="nodes">The nodes to take as source.</param> /// <param name="selectorText">A string containing one or more CSS selectors separated by commas.</param> /// <param name="scopeNode">The optional node to take as scope.</param> /// <returns>A HTMLCollection with all elements that match the selection.</returns> public static IHtmlCollection <IElement> QuerySelectorAll(this INodeList nodes, String selectorText, INode?scopeNode = null) { var scope = GetScope(scopeNode); var sg = CreateSelector(nodes, scope, selectorText); if (sg != null) { return(sg.MatchAll(nodes.OfType <IElement>(), scope)); } return(new HtmlCollection <IElement>(Array.Empty <IElement>())); }
/// <summary> /// Returns the first element within the document (using depth-first pre-order traversal /// of the document's nodes) that matches the specified group of selectors. /// Requires either a non-empty nodelist or a valid scope node. /// </summary> /// <param name="nodes">The nodes to take as source.</param> /// <param name="selectorText">A string containing one or more CSS selectors separated by commas.</param> /// <param name="scopeNode">The optional node to take as scope.</param> /// <returns>An element object.</returns> public static IElement?QuerySelector(this INodeList nodes, String selectorText, INode?scopeNode = null) { var scope = GetScope(scopeNode); var sg = CreateSelector(nodes, scope, selectorText); if (sg != null) { return(sg.MatchAny(nodes.OfType <IElement>(), scope)); } return(null); }