x
1
2
<html>
3
<body>
4
5
<p>Click the button to make changes to a list item, using the createDocumentFragment method, then appending the list item as the last child of the list.</p>
6
7
<ul><li>Coffee</li><li>Tea</li></ul>
8
9
<button onclick="myFunction()">Try it</button>
10
11
<script>
12
function myFunction() {
13
var d = document.createDocumentFragment();
14
d.appendChild(document.getElementsByTagName("LI")[0]);
15
d.childNodes[0].childNodes[0].nodeValue = "Milk";
16
document.getElementsByTagName("UL")[0].appendChild(d);
17
}
18
</script>
19
20
</body>
21
</html>