// Remove Element(s)
Element.prototype.remove = function() {
this.parentElement.removeChild(this);
}
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]);
}
}
}
Element.prototype.removeChildren = function() {
while (this.firstChild) {
this.removeChild(this.firstChild);
}
}
NodeList.prototype.removeChildren = HTMLCollection.prototype.removeChildren = function() {
for (var i = this.length - 1; i >= 0; i--) {
while (this[i].firstChild) {
this[i].removeChild(this[i].firstChild);
}
}
}
Created
November 14, 2015 02:24
-
-
Save danielhickman/5535ef8103da8a168a59 to your computer and use it in GitHub Desktop.
JavaScript Remove and Remove Children
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Partially from this StackOverflow answer