diff options
-rw-r--r-- | Userland/Libraries/LibWeb/DOM/Document.cpp | 14 | ||||
-rw-r--r-- | Userland/Libraries/LibWeb/DOM/Element.cpp | 14 |
2 files changed, 22 insertions, 6 deletions
diff --git a/Userland/Libraries/LibWeb/DOM/Document.cpp b/Userland/Libraries/LibWeb/DOM/Document.cpp index 0d21541a4d..af4430c3ca 100644 --- a/Userland/Libraries/LibWeb/DOM/Document.cpp +++ b/Userland/Libraries/LibWeb/DOM/Document.cpp @@ -933,10 +933,18 @@ JS::NonnullGCPtr<HTMLCollection> Document::get_elements_by_name(String const& na }); } -JS::NonnullGCPtr<HTMLCollection> Document::get_elements_by_class_name(FlyString const& class_name) +JS::NonnullGCPtr<HTMLCollection> Document::get_elements_by_class_name(FlyString const& class_names) { - return HTMLCollection::create(*this, [class_name, quirks_mode = document().in_quirks_mode()](Element const& element) { - return element.has_class(class_name, quirks_mode ? CaseSensitivity::CaseInsensitive : CaseSensitivity::CaseSensitive); + Vector<FlyString> list_of_class_names; + for (auto& name : class_names.view().split_view(' ')) { + list_of_class_names.append(name); + } + return HTMLCollection::create(*this, [list_of_class_names = move(list_of_class_names), quirks_mode = document().in_quirks_mode()](Element const& element) { + for (auto& name : list_of_class_names) { + if (!element.has_class(name, quirks_mode ? CaseSensitivity::CaseInsensitive : CaseSensitivity::CaseSensitive)) + return false; + } + return true; }); } diff --git a/Userland/Libraries/LibWeb/DOM/Element.cpp b/Userland/Libraries/LibWeb/DOM/Element.cpp index e5963cb29b..37219fb37d 100644 --- a/Userland/Libraries/LibWeb/DOM/Element.cpp +++ b/Userland/Libraries/LibWeb/DOM/Element.cpp @@ -507,10 +507,18 @@ bool Element::is_active() const return document().active_element() == this; } -JS::NonnullGCPtr<HTMLCollection> Element::get_elements_by_class_name(FlyString const& class_name) +JS::NonnullGCPtr<HTMLCollection> Element::get_elements_by_class_name(FlyString const& class_names) { - return HTMLCollection::create(*this, [class_name, quirks_mode = document().in_quirks_mode()](Element const& element) { - return element.has_class(class_name, quirks_mode ? CaseSensitivity::CaseInsensitive : CaseSensitivity::CaseSensitive); + Vector<FlyString> list_of_class_names; + for (auto& name : class_names.view().split_view(' ')) { + list_of_class_names.append(name); + } + return HTMLCollection::create(*this, [list_of_class_names = move(list_of_class_names), quirks_mode = document().in_quirks_mode()](Element const& element) { + for (auto& name : list_of_class_names) { + if (!element.has_class(name, quirks_mode ? CaseSensitivity::CaseInsensitive : CaseSensitivity::CaseSensitive)) + return false; + } + return true; }); } |