Created
January 7, 2011 11:59
-
-
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.
This file contains hidden or 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
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(); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.