dom: add element.HasAttributes

This commit is contained in:
Pierre Tachoire
2023-12-01 16:51:58 +01:00
parent acf737152c
commit dcb095d9df
2 changed files with 12 additions and 0 deletions

View File

@@ -27,6 +27,10 @@ pub const Element = struct {
return try parser.elementLocalName(self);
}
pub fn _hasAttributes(self: *parser.Element) !bool {
return try parser.nodeHasAttributes(parser.elementToNode(self));
}
pub fn _getAttribute(self: *parser.Element, qname: []const u8) !?[]const u8 {
return try parser.elementGetAttribute(self, qname);
}
@@ -84,6 +88,7 @@ pub fn testExecFn(
) !void {
var attribute = [_]Case{
.{ .src = "let a = document.getElementById('content')", .ex = "undefined" },
.{ .src = "a.hasAttributes()", .ex = "true" },
.{ .src = "a.getAttribute('id')", .ex = "content" },
.{ .src = "a.hasAttribute('foo')", .ex = "false" },