dom: implement getElementsByClassName

This commit is contained in:
Pierre Tachoire
2023-11-17 17:36:28 +01:00
parent e9edb8bab4
commit dd28204797
3 changed files with 48 additions and 0 deletions

View File

@@ -522,6 +522,11 @@ pub fn nodeReplaceChild(node: *Node, new_child: *Node, old_child: *Node) *Node {
return res.?;
}
// nodeToElement is an helper to convert a node to an element.
pub inline fn nodeToElement(node: *Node) *Element {
return @as(*Element, @ptrCast(node));
}
// CharacterData
pub const CharacterData = c.dom_characterdata;
@@ -621,6 +626,12 @@ pub fn elementGetAttribute(elem: *Element, name: []const u8) ?[]const u8 {
return stringToData(s.?);
}
pub fn elementHasClass(elem: *Element, class: []const u8) bool {
var res: bool = undefined;
_ = elementVtable(elem).dom_element_has_class.?(elem, stringFromData(class), &res);
return res;
}
// elementToNode is an helper to convert an element to a node.
pub inline fn elementToNode(e: *Element) *Node {
return @as(*Node, @ptrCast(e));