Created
December 12, 2021 17:38
-
-
Save YasirGaji/446ac598b391a2395ea2f8724e893e85 to your computer and use it in GitHub Desktop.
This gist showcases how to construct/create an element from scratch and append it to the dom its further explained in the DOD article by Yasir Gaji
This file contains 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
const li = document.createElement('li'); // this creates an "li" element | |
li.className = 'New-photo'; // this assigns a class to the "li" element | |
li.setAttribute('title', 'The new kid in town'); // this assigns an attribute to the "li" element | |
li.appendChild(document.createTextNode('The new list Item')); // this inputs a text node into the newly created "li" element | |
document.querySelector('ul.showcase').appendChild(li); // THIS WOULD APPEND THIS INTO THE EXISTING ELEMENTS IN THE INTERFACE |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment