Skip to content

Instantly share code, notes, and snippets.

@leaysgur
Created February 5, 2015 03:07
Show Gist options
  • Save leaysgur/6cfbd576d165c799747a to your computer and use it in GitHub Desktop.
Save leaysgur/6cfbd576d165c799747a to your computer and use it in GitHub Desktop.
removeAllElmExceptOne
var parentNode = document.body,
childNodes = parentNode.childNodes,
node;
while (1) {
// 1つを残して全部消す
if (childNodes.length === 1) {
break;
}
// 基本は先頭
node = childNodes[0];
// 残したいやつが見つかったら一つずらす
if ('id' in node && node.id === 'NOKOSU_ELM_ID') {
node = childNodes[1];
}
parentNode.removeChild(node);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment