1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 17:17:44 +00:00

LibWeb: Add an accessor for the document's title element

This commit is contained in:
Timothy Flynn 2023-06-07 15:13:42 -04:00 committed by Andreas Kling
parent e8fde316f6
commit 43b3673198
2 changed files with 21 additions and 0 deletions

View file

@ -631,6 +631,21 @@ HTML::HTMLHeadElement* Document::head()
return html->first_child_of_type<HTML::HTMLHeadElement>();
}
// https://html.spec.whatwg.org/multipage/dom.html#the-title-element-2
JS::GCPtr<HTML::HTMLTitleElement> Document::title_element()
{
// The title element of a document is the first title element in the document (in tree order), if there is one, or
// null otherwise.
JS::GCPtr<HTML::HTMLTitleElement> title_element = nullptr;
for_each_in_subtree_of_type<HTML::HTMLTitleElement>([&](auto& title_element_in_tree) {
title_element = title_element_in_tree;
return IterationDecision::Break;
});
return title_element;
}
HTML::HTMLElement* Document::body()
{
auto* html = html_element();