Skip to content

Instantly share code, notes, and snippets.

@YasirGaji
Created December 12, 2021 17:38
Show Gist options
  • Save YasirGaji/446ac598b391a2395ea2f8724e893e85 to your computer and use it in GitHub Desktop.
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
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