diff --git a/Userland/Libraries/LibWeb/DOM/Element.cpp b/Userland/Libraries/LibWeb/DOM/Element.cpp index d334d45990..919b3c8dec 100644 --- a/Userland/Libraries/LibWeb/DOM/Element.cpp +++ b/Userland/Libraries/LibWeb/DOM/Element.cpp @@ -234,6 +234,17 @@ bool Element::has_attribute(DeprecatedFlyString const& name) const return m_attributes->get_attribute(name) != nullptr; } +// https://dom.spec.whatwg.org/#dom-element-hasattributens +bool Element::has_attribute_ns(DeprecatedFlyString namespace_, DeprecatedFlyString const& name) const +{ + // 1. If namespace is the empty string, then set it to null. + if (namespace_.is_empty()) + namespace_ = {}; + + // 2. Return true if this has an attribute whose namespace is namespace and local name is localName; otherwise false. + return m_attributes->get_attribute_ns(namespace_, name) != nullptr; +} + // https://dom.spec.whatwg.org/#dom-element-toggleattribute WebIDL::ExceptionOr Element::toggle_attribute(DeprecatedFlyString const& name, Optional force) { diff --git a/Userland/Libraries/LibWeb/DOM/Element.h b/Userland/Libraries/LibWeb/DOM/Element.h index 1bc6bf2d31..403e078514 100644 --- a/Userland/Libraries/LibWeb/DOM/Element.h +++ b/Userland/Libraries/LibWeb/DOM/Element.h @@ -88,6 +88,7 @@ public: DeprecatedFlyString const& namespace_uri() const { return namespace_(); } bool has_attribute(DeprecatedFlyString const& name) const; + bool has_attribute_ns(DeprecatedFlyString namespace_, DeprecatedFlyString const& name) const; bool has_attributes() const; DeprecatedString attribute(DeprecatedFlyString const& name) const { return get_attribute(name); } DeprecatedString get_attribute(DeprecatedFlyString const& name) const; diff --git a/Userland/Libraries/LibWeb/DOM/Element.idl b/Userland/Libraries/LibWeb/DOM/Element.idl index aeb3f55caa..8b37157383 100644 --- a/Userland/Libraries/LibWeb/DOM/Element.idl +++ b/Userland/Libraries/LibWeb/DOM/Element.idl @@ -35,6 +35,7 @@ interface Element : Node { [CEReactions] undefined removeAttribute(DOMString qualifiedName); [CEReactions] boolean toggleAttribute(DOMString qualifiedName, optional boolean force); boolean hasAttribute(DOMString qualifiedName); + boolean hasAttributeNS(DOMString? namespace, DOMString localName); boolean hasAttributes(); [SameObject] readonly attribute NamedNodeMap attributes; sequence getAttributeNames();