Javascript DOM Document Create Fragment and Append

Description

Javascript DOM Document Create Fragment and Append

View in separate window


<html>
<head>
    <title>Creating DocumentFragments and Appending them</title>
</head>/* www .ja  v a  2s .  c  o  m*/
<body>
<script type="text/javascript">
  let aFragment = document.createDocumentFragment();
  for (let i = 0; i < 20; i++) {
    let newParagraph = document.createElement("p");
    let newText = "Hello World.";
    newParagraph.innerText = newText;
    newParagraph.textContent = newText;
    aFragment.appendChild(newParagraph); 
  }
  document.body.appendChild(aFragment);
</script>
</body>
</html>



PreviousNext

Related