summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Libraries/LibWeb/DOM/Document.cpp11
-rw-r--r--Libraries/LibWeb/DOM/Document.h1
-rw-r--r--Libraries/LibWeb/DOM/Document.idl1
3 files changed, 13 insertions, 0 deletions
diff --git a/Libraries/LibWeb/DOM/Document.cpp b/Libraries/LibWeb/DOM/Document.cpp
index 8016a40225..c57d7e06c7 100644
--- a/Libraries/LibWeb/DOM/Document.cpp
+++ b/Libraries/LibWeb/DOM/Document.cpp
@@ -458,6 +458,17 @@ NonnullRefPtrVector<Element> Document::get_elements_by_tag_name(const FlyString&
return elements;
}
+NonnullRefPtrVector<Element> Document::get_elements_by_class_name(const FlyString& class_name) const
+{
+ NonnullRefPtrVector<Element> elements;
+ for_each_in_subtree_of_type<Element>([&](auto& element) {
+ if (element.has_class(class_name))
+ elements.append(element);
+ return IterationDecision::Continue;
+ });
+ return elements;
+}
+
Color Document::link_color() const
{
if (m_link_color.has_value())
diff --git a/Libraries/LibWeb/DOM/Document.h b/Libraries/LibWeb/DOM/Document.h
index 77e9b12039..5c4d82b094 100644
--- a/Libraries/LibWeb/DOM/Document.h
+++ b/Libraries/LibWeb/DOM/Document.h
@@ -132,6 +132,7 @@ public:
NonnullRefPtrVector<Element> get_elements_by_name(const String&) const;
NonnullRefPtrVector<Element> get_elements_by_tag_name(const FlyString&) const;
+ NonnullRefPtrVector<Element> get_elements_by_class_name(const FlyString&) const;
const String& source() const { return m_source; }
void set_source(const String& source) { m_source = source; }
diff --git a/Libraries/LibWeb/DOM/Document.idl b/Libraries/LibWeb/DOM/Document.idl
index a6610cd8d1..ce50d7d7b2 100644
--- a/Libraries/LibWeb/DOM/Document.idl
+++ b/Libraries/LibWeb/DOM/Document.idl
@@ -9,6 +9,7 @@ interface Document : Node {
Element? getElementById(DOMString id);
ArrayFromVector getElementsByTagName(DOMString tagName);
+ ArrayFromVector getElementsByClassName(DOMString className);
readonly attribute Element? firstElementChild;
readonly attribute Element? lastElementChild;