File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -114,6 +114,7 @@ class HTMLElement{
114114 this removeWhitespace()
115115 Node[] querySelectorAll(string selector)
116116 Node querySelector(string selector)
117+ this matches(string selector)
117118 HTMLElement[] getElementsByTagName(string tagName)
118119 Node closest(string selector)
119120 Node appendChild(Node node)
@@ -208,6 +209,10 @@ Note: Full range of CSS3 selectors supported since v3.0.0.
208209
209210Query CSS Selector to find matching node. ` null ` if not found.
210211
212+ ### matches(selector)
213+
214+ Tests whether the node matches a given CSS selector.
215+
211216### getElementsByTagName(tagName)
212217
213218Get all elements with the specified tagName.
Original file line number Diff line number Diff line change 1- import { selectAll , selectOne } from 'css-select' ;
1+ import { is , selectAll , selectOne } from 'css-select' ;
22import he from 'he' ;
33import arr_back from '../back' ;
44import Matcher from '../matcher' ;
@@ -498,6 +498,18 @@ export default class HTMLElement extends Node {
498498 } ) ;
499499 }
500500
501+ /**
502+ * Tests whether the node matches a given CSS selector.
503+ * @param {string } selector Simplified CSS selector
504+ * @return {boolean }
505+ */
506+ public matches ( selector : string ) : boolean {
507+ return is ( this as HTMLElement , selector , {
508+ xmlMode : true ,
509+ adapter : Matcher ,
510+ } ) ;
511+ }
512+
501513 /**
502514 * find elements by their tagName
503515 * @param {string } tagName the tagName of the elements to select
You can’t perform that action at this time.
0 commit comments