Last active
December 12, 2021 20:18
-
-
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
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 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