diff --git a/Libraries/LibWeb/DOM/Document.cpp b/Libraries/LibWeb/DOM/Document.cpp index 34ea160b00..7191b42a68 100644 --- a/Libraries/LibWeb/DOM/Document.cpp +++ b/Libraries/LibWeb/DOM/Document.cpp @@ -132,9 +132,17 @@ const Element* Document::document_element() const return first_child_of_type(); } -const HTML::HTMLHeadElement* Document::head() const +const HTML::HTMLHtmlElement* Document::html_element() const { auto* html = document_element(); + if (is(html)) + return downcast(html); + return nullptr; +} + +const HTML::HTMLHeadElement* Document::head() const +{ + auto* html = html_element(); if (!html) return nullptr; return html->first_child_of_type(); @@ -142,7 +150,7 @@ const HTML::HTMLHeadElement* Document::head() const const HTML::HTMLElement* Document::body() const { - auto* html = document_element(); + auto* html = html_element(); if (!html) return nullptr; return html->first_child_of_type(); diff --git a/Libraries/LibWeb/DOM/Document.h b/Libraries/LibWeb/DOM/Document.h index 5bdac924b7..5e1737c692 100644 --- a/Libraries/LibWeb/DOM/Document.h +++ b/Libraries/LibWeb/DOM/Document.h @@ -86,6 +86,7 @@ public: const Node* inspected_node() const { return m_inspected_node; } const Element* document_element() const; + const HTML::HTMLHtmlElement* html_element() const; const HTML::HTMLHeadElement* head() const; const HTML::HTMLElement* body() const;