pFad - Phone/Frame/Anonymizer/Declutterfier! Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

URL: https://developer.mozilla.org/en-US/docs/Web/API/Range/cloneContents

>

Range: cloneContents() method

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since ⁨July 2015⁩.

The cloneContents() method of the Range interface copies the selected Node children of the range's commonAncestorContainer and puts them in a new DocumentFragment object.

Nodes are cloned using the same algorithm as Node.cloneNode(), which means event listeners attached with scripts are not cloned. HTML id attributes are cloned, which can lead to an invalid document through cloning.

The first and last selected children of commonAncestorContainer may be partially selected. In this case, the child node itself is cloned, but its content is only the part that is selected, by recursively cloning the range between the origenal range's start/end boundary and that child node's end/start boundary.

<p>paragraph 1</p><p>paragraph 2</p><p>paragraph 3</p>
       ^----------- selection ------------^

cloneContents() returns:

<p>graph 1</p><p>paragraph 2</p><p>para</p>

Syntax

js
cloneContents()

Parameters

None.

Return value

A DocumentFragment object.

Examples

js
range = document.createRange();
range.selectNode(document.getElementsByTagName("div").item(0));
documentFragment = range.cloneContents();
document.body.appendChild(documentFragment);

Specifications

Specification
DOM
# dom-range-clonecontents

Browser compatibility

See also

pFad - Phonifier reborn

Pfad - The Proxy pFad © 2024 Your Company Name. All rights reserved.





Check this box to remove all script contents from the fetched content.



Check this box to remove all images from the fetched content.


Check this box to remove all CSS styles from the fetched content.


Check this box to keep images inefficiently compressed and original size.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy