@@ -355,7 +355,12 @@ pub const Element = struct {
355355 return state .renderer .height ();
356356 }
357357
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+ }
359364};
360365
361366// Tests
@@ -518,4 +523,13 @@ test "Browser.DOM.Element" {
518523 .{ "document.getElementById('para').clientWidth" , "2" },
519524 .{ "document.getElementById('para').clientHeight" , "1" },
520525 }, .{});
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+ }, .{});
521535}
0 commit comments