Skip to content

Commit

Permalink
LibWeb: Make Element::is_document_element() slightly nicer
Browse files Browse the repository at this point in the history
By following the spec more closely, we can actually make this function
a bit more efficient (by comparing the parent against the document
instead of looking for the first element child of the document).
  • Loading branch information
awesomekling committed Mar 13, 2024
1 parent 733a9c0 commit a8559f4
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion Userland/Libraries/LibWeb/DOM/Element.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -777,7 +777,8 @@ bool Element::is_target() const
// https://dom.spec.whatwg.org/#document-element
bool Element::is_document_element() const
{
return document().document_element() == this;
// The document element of a document is the element whose parent is that document, if it exists; otherwise null.
return parent() == &document();
}

JS::NonnullGCPtr<HTMLCollection> Element::get_elements_by_class_name(StringView class_names)
Expand Down

0 comments on commit a8559f4

Please sign in to comment.