Sfoglia il codice sorgente

LibWeb: Add Element::is_document_element() helper

This is *not* the same as `Node::is_document()`, just to be confusing.
It basically means it's the root element.
Sam Atkins 2 anni fa
parent
commit
9f83c0f0da

+ 6 - 0
Userland/Libraries/LibWeb/DOM/Element.cpp

@@ -639,6 +639,12 @@ bool Element::is_target() const
     return document().target_element() == this;
 }
 
+// https://dom.spec.whatwg.org/#document-element
+bool Element::is_document_element() const
+{
+    return document().document_element() == this;
+}
+
 JS::NonnullGCPtr<HTMLCollection> Element::get_elements_by_class_name(DeprecatedFlyString const& class_names)
 {
     Vector<FlyString> list_of_class_names;

+ 1 - 0
Userland/Libraries/LibWeb/DOM/Element.h

@@ -169,6 +169,7 @@ public:
     bool is_focused() const;
     bool is_active() const;
     bool is_target() const;
+    bool is_document_element() const;
 
     JS::NonnullGCPtr<HTMLCollection> get_elements_by_class_name(DeprecatedFlyString const&);