mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 21:57:43 +00:00
LibWeb: Implement Document.getElementsByClassName()
Note that we're taking a shortcut here and returning the elements as an Array instead of HTMLCollection. One day we'll have to bite the bullet and deal with HTMLCollection, but not today.
This commit is contained in:
parent
09da5f7263
commit
7c4c706ebe
3 changed files with 13 additions and 0 deletions
|
@ -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())
|
||||
|
|
|
@ -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; }
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue