Skip to content

Instantly share code, notes, and snippets.

@YasirGaji
Last active December 12, 2021 20:18
Show Gist options
  • Save YasirGaji/5f2a917c8701c7a40fff4fda6f108997 to your computer and use it in GitHub Desktop.
Save YasirGaji/5f2a917c8701c7a40fff4fda6f108997 to your computer and use it in GitHub Desktop.
This gist replaces an element in the Dom with a newly created element its further explained in the DOD article by Yasir Gaji
const newHeading = document.createElement('h1'); // this creates a new element which in this case a "h1" element
newHeading.appendChild(document.createTextNode('Taking over this space!!')); // assigning a text node to the newly created element
const oldHeading = document.querySelector('li.photo'); // initializing the element to be replaced to a variable
const ulElement = document.querySelector('ul.showcase'); // initializing the parent element
ulElement.replaceChild(newHeading, oldHeading); // THIS REPLACES THE OLD ELEMENT WITH THE NEW ONE
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment