diff --git a/Tests/LibWeb/Text/expected/DOM/Element-getAttributeNodeNS.txt b/Tests/LibWeb/Text/expected/DOM/Element-getAttributeNodeNS.txt new file mode 100644 index 0000000000..80e81282c7 --- /dev/null +++ b/Tests/LibWeb/Text/expected/DOM/Element-getAttributeNodeNS.txt @@ -0,0 +1,4 @@ + xlink:href getAttributeNode = 'null' +xlink:href getAttributeNodeNS = 'Attr': name = xlink:href value = test +href getAttributeNode = 'Attr': name = href value = test +href getAttributeNodeNS = 'null' diff --git a/Tests/LibWeb/Text/input/DOM/Element-getAttributeNodeNS.html b/Tests/LibWeb/Text/input/DOM/Element-getAttributeNodeNS.html new file mode 100644 index 0000000000..5cb4f15d9f --- /dev/null +++ b/Tests/LibWeb/Text/input/DOM/Element-getAttributeNodeNS.html @@ -0,0 +1,23 @@ + + + + + + diff --git a/Userland/Libraries/LibWeb/DOM/Element.cpp b/Userland/Libraries/LibWeb/DOM/Element.cpp index 4767b385c1..815408acdf 100644 --- a/Userland/Libraries/LibWeb/DOM/Element.cpp +++ b/Userland/Libraries/LibWeb/DOM/Element.cpp @@ -164,6 +164,13 @@ JS::GCPtr Element::get_attribute_node(FlyString const& name) const return m_attributes->get_attribute(name); } +// https://dom.spec.whatwg.org/#dom-element-getattributenodens +JS::GCPtr Element::get_attribute_node_ns(Optional const& namespace_, FlyString const& name) const +{ + // The getAttributeNodeNS(namespace, localName) method steps are to return the result of getting an attribute given namespace, localName, and this. + return m_attributes->get_attribute_ns(namespace_, name); +} + // https://dom.spec.whatwg.org/#dom-element-setattribute WebIDL::ExceptionOr Element::set_attribute(FlyString const& name, String const& value) { diff --git a/Userland/Libraries/LibWeb/DOM/Element.h b/Userland/Libraries/LibWeb/DOM/Element.h index d14a94f6be..30bd2870a3 100644 --- a/Userland/Libraries/LibWeb/DOM/Element.h +++ b/Userland/Libraries/LibWeb/DOM/Element.h @@ -119,6 +119,7 @@ public: Vector get_attribute_names() const; JS::GCPtr get_attribute_node(FlyString const& name) const; + JS::GCPtr get_attribute_node_ns(Optional const& namespace_, FlyString const& name) const; DOMTokenList* class_list(); diff --git a/Userland/Libraries/LibWeb/DOM/Element.idl b/Userland/Libraries/LibWeb/DOM/Element.idl index de4a94cd8f..f4c5eb5ea3 100644 --- a/Userland/Libraries/LibWeb/DOM/Element.idl +++ b/Userland/Libraries/LibWeb/DOM/Element.idl @@ -43,7 +43,8 @@ interface Element : Node { [SameObject] readonly attribute NamedNodeMap attributes; sequence getAttributeNames(); - Attr? getAttributeNode(DOMString qualifiedName); + Attr? getAttributeNode([FlyString] DOMString qualifiedName); + Attr? getAttributeNodeNS([FlyString] DOMString? namespace, [FlyString] DOMString localName); HTMLCollection getElementsByTagName(DOMString tagName); HTMLCollection getElementsByTagNameNS(DOMString? namespace, DOMString localName);