diff --git a/Userland/Libraries/LibWeb/DOM/Element.cpp b/Userland/Libraries/LibWeb/DOM/Element.cpp index f421cde0f0..7e85c9263b 100644 --- a/Userland/Libraries/LibWeb/DOM/Element.cpp +++ b/Userland/Libraries/LibWeb/DOM/Element.cpp @@ -109,6 +109,18 @@ bool Element::has_attribute(const FlyString& name) const return m_attributes->get_attribute(name) != nullptr; } +// https://dom.spec.whatwg.org/#dom-element-getattributenames +Vector Element::get_attribute_names() const +{ + // The getAttributeNames() method steps are to return the qualified names of the attributes in this’s attribute list, in order; otherwise a new list. + Vector names; + for (size_t i = 0; i < m_attributes->length(); ++i) { + auto const* attribute = m_attributes->item(i); + names.append(attribute->name()); + } + return names; +} + bool Element::has_class(const FlyString& class_name, CaseSensitivity case_sensitivity) const { return any_of(m_classes, [&](auto& it) { diff --git a/Userland/Libraries/LibWeb/DOM/Element.h b/Userland/Libraries/LibWeb/DOM/Element.h index 7e6f09b24d..b037e18438 100644 --- a/Userland/Libraries/LibWeb/DOM/Element.h +++ b/Userland/Libraries/LibWeb/DOM/Element.h @@ -57,6 +57,7 @@ public: void remove_attribute(const FlyString& name); size_t attribute_list_size() const { return m_attributes->length(); } NonnullRefPtr const& attributes() const { return m_attributes; } + Vector get_attribute_names() const; RefPtr const& class_list(); diff --git a/Userland/Libraries/LibWeb/DOM/Element.idl b/Userland/Libraries/LibWeb/DOM/Element.idl index fc7629c723..bb4aa457c9 100644 --- a/Userland/Libraries/LibWeb/DOM/Element.idl +++ b/Userland/Libraries/LibWeb/DOM/Element.idl @@ -10,6 +10,7 @@ interface Element : Node { boolean hasAttribute(DOMString qualifiedName); boolean hasAttributes(); [SameObject] readonly attribute NamedNodeMap attributes; + sequence getAttributeNames(); HTMLCollection getElementsByTagName(DOMString tagName); HTMLCollection getElementsByTagNameNS(DOMString? namespace, DOMString localName);