Skip to content

Instantly share code, notes, and snippets.

@jaikdean
Created January 7, 2011 11:59
Show Gist options
  • Save jaikdean/769393 to your computer and use it in GitHub Desktop.
Save jaikdean/769393 to your computer and use it in GitHub Desktop.
This allows you to destroy an Element but leave its contents, including other Elements and text nodes, in its place.
Element.implement({
removeTag: function(){
var childNodes = this.childNodes;
for (var i = childNodes.length - 1; i >= 0; i--) {
if (childNodes[i].nodeType == document.TEXT_NODE) {
this.appendText(childNodes[i].nodeValue, 'after');
} else {
document.id(childNodes[i]).inject(this, 'after');
}
}
this.destroy();
}
});
@jaikdean
Copy link
Author

jaikdean commented Jan 7, 2011

HTML:



This text will be in place of the removeMe element.

JS:
$('removeMe').removeTag();

Output:


This text will be in place of the removeMe element.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment