The createDocumentFragment()
method creates a
Node object.
createDocumentFragment |
Yes | Yes | Yes | Yes | Yes |
document.createDocumentFragment()
None.
A DocumentFragment object
The following code shows how to create a documentFragment node and append a child to it.
<!DOCTYPE html>
<html>
<body>
<ul><li>A</li><li>B</li></ul>
<button onclick="myFunction()">test</button>
<script>
function myFunction()<!--from www .java 2s .co m-->
{
var d=document.createDocumentFragment();
d.appendChild(document.getElementsByTagName("LI")[0]);
d.childNodes[0].childNodes[0].nodeValue="new";
document.getElementsByTagName("UL")[0].appendChild(d);
}
</script>
</body>
</html>
The code above is rendered as follows: