LibWeb: Ensure ParentNode.getElementsByClassName()
matches all classes
This commit is contained in:
parent
14267b5d63
commit
96c0cbf584
Notes:
github-actions[bot]
2024-08-04 08:40:05 +00:00
Author: https://github.com/tcl3 Commit: https://github.com/LadybirdBrowser/ladybird/commit/96c0cbf584e Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/947
3 changed files with 25 additions and 3 deletions
|
@ -0,0 +1,4 @@
|
||||||
|
document.getElementsByClassName("te st").length: 3
|
||||||
|
<DIV id="1" >
|
||||||
|
<DIV id="2" >
|
||||||
|
<DIV id="3" >
|
|
@ -0,0 +1,17 @@
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<script src="../include.js"></script>
|
||||||
|
<div id="1" class="te st"></div>
|
||||||
|
<div id="2" class="st te"></div>
|
||||||
|
<div id="3" class="te te st"></div>
|
||||||
|
<div id="4" class="te te"></div>
|
||||||
|
<div id="5" class="st st"></div>
|
||||||
|
<div id="6" class="test"></div>
|
||||||
|
<script>
|
||||||
|
test(() => {
|
||||||
|
let elements = document.getElementsByClassName("te st");
|
||||||
|
println(`document.getElementsByClassName("te st").length: ${elements.length}`);
|
||||||
|
for (let element of elements) {
|
||||||
|
printElement(element);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
</script>
|
|
@ -227,6 +227,7 @@ WebIDL::ExceptionOr<void> ParentNode::replace_children(Vector<Variant<JS::Handle
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// https://dom.spec.whatwg.org/#dom-document-getelementsbyclassname
|
||||||
JS::NonnullGCPtr<HTMLCollection> ParentNode::get_elements_by_class_name(StringView class_names)
|
JS::NonnullGCPtr<HTMLCollection> ParentNode::get_elements_by_class_name(StringView class_names)
|
||||||
{
|
{
|
||||||
Vector<FlyString> list_of_class_names;
|
Vector<FlyString> list_of_class_names;
|
||||||
|
@ -235,10 +236,10 @@ JS::NonnullGCPtr<HTMLCollection> ParentNode::get_elements_by_class_name(StringVi
|
||||||
}
|
}
|
||||||
return HTMLCollection::create(*this, HTMLCollection::Scope::Descendants, [list_of_class_names = move(list_of_class_names), quirks_mode = document().in_quirks_mode()](Element const& element) {
|
return HTMLCollection::create(*this, HTMLCollection::Scope::Descendants, [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) {
|
for (auto& name : list_of_class_names) {
|
||||||
if (element.has_class(name, quirks_mode ? CaseSensitivity::CaseInsensitive : CaseSensitivity::CaseSensitive))
|
if (!element.has_class(name, quirks_mode ? CaseSensitivity::CaseInsensitive : CaseSensitivity::CaseSensitive))
|
||||||
return true;
|
return false;
|
||||||
}
|
}
|
||||||
return false;
|
return !list_of_class_names.is_empty();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue