Skip to content

Instantly share code, notes, and snippets.

@YasirGaji
Created December 13, 2021 06:15
Show Gist options
  • Save YasirGaji/330561450aafae17e35edaadfc8d0d27 to your computer and use it in GitHub Desktop.
Save YasirGaji/330561450aafae17e35edaadfc8d0d27 to your computer and use it in GitHub Desktop.
This gist showcases how to remove child elements using javascript its further explained in the DOD article by Yasir Gaji
const liElements = document.querySelectorAll('li'); // this initializes "liElements" as a variable to represent all the "li" elements in the Html collection
const list = document.querySelector('ul'); // this initializes "list" as a variable to represent the "ul" element in the Html collection
list.removeChild(liElements[3]); // THIS EXECUTES THE MAIN TASK BY TAKING OUT THE 4TH "li" ELEMENT IN THE "ul" USING THE ".removeChild()" METHOD
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment