<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
<div id="app">
<input type="text" id="a">
<span id="b">222</span>
</div>
<div id="ap">
</div>
<script>
function nodetofragment(node){
let n = 0
var flag = document.createDocumentFragment();
var child;
while(child = node.firstChild){
flag.appendChild(child)
console.log(nPP)
}
return flag;
}
var dom = nodetofragment(document.getElementById("app"))
console.log(dom);
</script>
</body>
</html>
after four while loops in this code, I don"t understand why, and the loop conditions of while are not very clear.
after the execution of this code, the input and span in the page disappear.
execution result:
Wanwang solution