diff --git a/Userland/Libraries/LibWeb/DOM/Document.idl b/Userland/Libraries/LibWeb/DOM/Document.idl index c5229063f0..173b73cca7 100644 --- a/Userland/Libraries/LibWeb/DOM/Document.idl +++ b/Userland/Libraries/LibWeb/DOM/Document.idl @@ -66,6 +66,7 @@ interface Document : Node { readonly attribute unsigned long childElementCount; [CEReactions, Unscopable] undefined prepend((Node or DOMString)... nodes); + [CEReactions, Unscopable] undefined append((Node or DOMString)... nodes); Element? querySelector(DOMString selectors); [NewObject] NodeList querySelectorAll(DOMString selectors); diff --git a/Userland/Libraries/LibWeb/DOM/DocumentFragment.idl b/Userland/Libraries/LibWeb/DOM/DocumentFragment.idl index 938e05e9e9..5309a72957 100644 --- a/Userland/Libraries/LibWeb/DOM/DocumentFragment.idl +++ b/Userland/Libraries/LibWeb/DOM/DocumentFragment.idl @@ -10,6 +10,7 @@ interface DocumentFragment : Node { readonly attribute unsigned long childElementCount; [CEReactions, Unscopable] undefined prepend((Node or DOMString)... nodes); + [CEReactions, Unscopable] undefined append((Node or DOMString)... nodes); Element? querySelector(DOMString selectors); [NewObject] NodeList querySelectorAll(DOMString selectors); diff --git a/Userland/Libraries/LibWeb/DOM/Element.idl b/Userland/Libraries/LibWeb/DOM/Element.idl index c796cdd9c8..66da1ec84f 100644 --- a/Userland/Libraries/LibWeb/DOM/Element.idl +++ b/Userland/Libraries/LibWeb/DOM/Element.idl @@ -39,6 +39,7 @@ interface Element : Node { readonly attribute unsigned long childElementCount; [CEReactions, Unscopable] undefined prepend((Node or DOMString)... nodes); + [CEReactions, Unscopable] undefined append((Node or DOMString)... nodes); Element? querySelector(DOMString selectors); [NewObject] NodeList querySelectorAll(DOMString selectors); diff --git a/Userland/Libraries/LibWeb/DOM/ParentNode.cpp b/Userland/Libraries/LibWeb/DOM/ParentNode.cpp index 24d8675ea9..b2587bb396 100644 --- a/Userland/Libraries/LibWeb/DOM/ParentNode.cpp +++ b/Userland/Libraries/LibWeb/DOM/ParentNode.cpp @@ -174,4 +174,21 @@ ExceptionOr ParentNode::prepend(Vector, String return {}; } +ExceptionOr ParentNode::append(Vector, String>> const& nodes) +{ + // 1. Let node be the result of converting nodes into a node given nodes and this’s node document. + auto node_or_exception = convert_nodes_to_single_node(nodes, document()); + if (node_or_exception.is_exception()) + return node_or_exception.exception(); + + auto node = node_or_exception.release_value(); + + // 2. Append node to this. + auto result = append_child(node); + if (result.is_exception()) + return result.exception(); + + return {}; +} + } diff --git a/Userland/Libraries/LibWeb/DOM/ParentNode.h b/Userland/Libraries/LibWeb/DOM/ParentNode.h index feaa1a73c8..e3ee6abf08 100644 --- a/Userland/Libraries/LibWeb/DOM/ParentNode.h +++ b/Userland/Libraries/LibWeb/DOM/ParentNode.h @@ -31,6 +31,7 @@ public: NonnullRefPtr get_elements_by_tag_name_ns(FlyString const&, FlyString const&); ExceptionOr prepend(Vector, String>> const& nodes); + ExceptionOr append(Vector, String>> const& nodes); protected: ParentNode(Document& document, NodeType type)