Created
October 6, 2018 15:11
-
-
Save prof3ssorSt3v3/de9d00cc831049ca59232d6a1315cb73 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <!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