Skip to content

Instantly share code, notes, and snippets.

@zhanhongtao
Created October 8, 2013 06:57
Show Gist options
  • Save zhanhongtao/6880649 to your computer and use it in GitHub Desktop.
Save zhanhongtao/6880649 to your computer and use it in GitHub Desktop.
remove element by class
function removeDomByClass( classname ) {
var boxes = document.getElementsByClassName( classname );
for ( var i = 0, l = boxes.length; i < l; i++ ) {
var box = boxes[0];
if ( box && box.parentNode ) {
box.parentNode.removeChild( box );
}
}
}
function removeDomByClass2( classname ) {
var boxes = document.getElementsByClassName( classname );
while ( boxes.length ) {
var box = boxes[0];
box.parentNode.removeChild( box );
}
}
function removeDomByClass3( classname ) {
var boxes = document.querySelectorAll( '.' + classname );
for ( var i = 0; i < boxes.length; i++ ) {
var box = boxes[i];
box.parentNode.removeChild( box );
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment