@@ -355,7 +355,12 @@ pub const Element = struct {
355
355
return state .renderer .height ();
356
356
}
357
357
358
- pub fn deinit (_ : * parser.Element , _ : std.mem.Allocator ) void {}
358
+ pub fn _matches (self : * parser.Element , selectors : []const u8 , state : * SessionState ) ! bool {
359
+ const cssParse = @import ("../css/css.zig" ).parse ;
360
+ const CssNodeWrap = @import ("../css/libdom.zig" ).Node ;
361
+ const s = try cssParse (state .call_arena , selectors , .{});
362
+ return s .match (CssNodeWrap { .node = parser .elementToNode (self ) });
363
+ }
359
364
};
360
365
361
366
// Tests
@@ -518,4 +523,13 @@ test "Browser.DOM.Element" {
518
523
.{ "document.getElementById('para').clientWidth" , "2" },
519
524
.{ "document.getElementById('para').clientHeight" , "1" },
520
525
}, .{});
526
+
527
+ try runner .testCases (&.{
528
+ .{ "const el = document.createElement('div');" , "undefined" },
529
+ .{ "el.id = 'matches'; el.className = 'ok';" , "ok" },
530
+ .{ "el.matches('#matches')" , "true" },
531
+ .{ "el.matches('.ok')" , "true" },
532
+ .{ "el.matches('#9000')" , "false" },
533
+ .{ "el.matches('.notok')" , "false" },
534
+ }, .{});
521
535
}
0 commit comments