diff --git a/files/en-us/web/api/documentfragment/index.html b/files/en-us/web/api/documentfragment/index.html index 201561713346262..d512fd0f3daed18 100644 --- a/files/en-us/web/api/documentfragment/index.html +++ b/files/en-us/web/api/documentfragment/index.html @@ -43,6 +43,8 @@

Methods

{{DOMxRef("DocumentFragment.append()")}}
Inserts a set of {{domxref("Node")}} objects or {{domxref("DOMString")}} objects after the last child of the document fragment.
+
{{DOMxRef("DocumentFragment.prepend()")}}
+
Inserts a set of {{domxref("Node")}} objects or {{domxref("DOMString")}} objects before the first child of the document fragment.
{{domxref("DocumentFragment.querySelector()")}}
Returns the first {{domxref("Element")}} node within the DocumentFragment, in document order, that matches the specified selectors.
{{domxref("DocumentFragment.querySelectorAll()")}}
diff --git a/files/en-us/web/api/documentfragment/prepend/index.html b/files/en-us/web/api/documentfragment/prepend/index.html new file mode 100644 index 000000000000000..a810aec7ab920d3 --- /dev/null +++ b/files/en-us/web/api/documentfragment/prepend/index.html @@ -0,0 +1,79 @@ +--- +title: DocumentFragment.prepend() +slug: Web/API/DocumentFragment/prepend +tags: + - API + - DOM + - Method + - Node + - DocumentFragment + - Reference +--- +

{{APIRef("DOM")}}

+ +

The DocumentFragment.prepend() method + inserts a set of {{domxref("Node")}} objects or {{domxref("DOMString")}} objects before + the first child of the document fragment. {{domxref("DOMString")}} objects + are inserted as equivalent {{domxref("Text")}} nodes.

+ +

This method prepends a child to a DocumentFragment. To prepend to an arbitrary element in the tree, see {{domxref("Element.prepend()")}}.

+ +

Syntax

+ +
+prepend(...nodesOrDOMStrings)
+
+ +

Parameters

+ +
+
nodesOrDOMStrings
+
A set of {{domxref("Node")}} or {{domxref("DOMString")}} objects to insert.
+
+ +

Exceptions

+ + + +

Examples

+ +

Prepending an element to a document fragment

+ +
+let fragment = new DocumentFragment();
+let div = document.createElement("div");
+let p = document.createElement("p");
+fragment.append(p);
+fragment.prepend(div);
+
+fragment.children; // HTMLCollection [<div>, <p>]
+
+ +

Specifications

+ + + + + + + + + + + + +
Specification
{{SpecName('DOM WHATWG', '#dom-parentnode-prepend', 'ParentNode.prepend()')}}
+ +

Browser compatibility

+ +

{{Compat("api.DocumentFragment.prepend")}}

+ +

See also

+ +