Skip to content

Instantly share code, notes, and snippets.

@TheRolfFR
Created October 3, 2021 11:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save TheRolfFR/a15291208e3138d6c1f64aec2b5736d7 to your computer and use it in GitHub Desktop.
Save TheRolfFR/a15291208e3138d6c1f64aec2b5736d7 to your computer and use it in GitHub Desktop.
Removes all elements from a NodeList. This NodeList is generally a document element query result.
/**
* Removes all elements from a NodeList.
* This NodeList is generally a document element query result.
* @author TheRolf
*/
NodeList.prototype.remove = HTMLCollection.prototype.remove = function() {
for(var i = this.length - 1; i >= 0; i--) {
if(this[i] && this[i].parentElement) {
this[i].parentElement.removeChild(this[i])
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment