Skip to content

Instantly share code, notes, and snippets.

@prof3ssorSt3v3
Created October 6, 2018 15:11
Show Gist options
  • Select an option

  • Save prof3ssorSt3v3/de9d00cc831049ca59232d6a1315cb73 to your computer and use it in GitHub Desktop.

Select an option

Save prof3ssorSt3v3/de9d00cc831049ca59232d6a1315cb73 to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document Fragments</title>
</head>
<body>
<div class="container">
<main>
<ul id="my-list">
<!-- my list will go here -->
</ul>
</main>
</div>
<script async>
let list = document.getElementById('my-list');
let people = ['Eric Meyer', 'Dan Cederholm', 'Jini Bolton', 'Rachel Andrew', 'Jonathan Snook', 'Derek Featherstone', 'Tim Berners-Lee'];
let df = document.createDocumentFragment();
people.forEach( (name, idx) => {
let li = document.createElement('li');
li.textContent = name;
df.appendChild(li);
//list.appendChild(li) && console.log(idx, 'Some bastard just made me update the DOM');
});
list.appendChild(df);
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment