document - Javascript | How to erase anything (divs, p's, a's, ...) which has not class ".destroy"? -


how can make work pure javascript? erase (divs, ps, as, spans, imgs, ...) in body section of html document has not class"destroy".

ps.: pure javascript means: no jquery or other frameworks..

you walk dom recursively , check every node class. this

function walk_the_dom(node) {     if (node.classname && (node.classname.indexof("destroy")>-1)) {         node.parentnode.removechild(node);     } else {       node = node.firstchild;       while (node) {        walk_the_dom(node);        node = node.nextsibling;       }     }  };  walk_the_dom(document.body); 

Comments