Last Updated: February 25, 2016
·
886
· jzazove

Remove all the text from a web page using Javascript

<h2>
(function(){
var a = document.querySelectorAll("body *")

, i = a.length
, child
, children
, x
;
while(i--){
    children = a[i].childNodes, 
    x = children.length;
    while(x--){
        var child = children[x];
        if(a[i].hasChildNodes() && child.nodeType === 3) {
            child.nodeValue = "";
        };
    };
    if(a[i].tagName.toLowerCase() === "input" || a[i].tagName.toLowerCase() === "textarea"){
            a[i].value = "";
            a[i].setAttribute("placeholder", "");   
    } else if(a[i].tagName.toLowerCase() === "iframe"){
            a[i].style.visibility = "hidden";
    };

};  

})();
</h2></pre>


it's on Github

https://github.com/jzazove/notext

1 Response
Add your response

this is great... but pretty useless :))

over 1 year ago ·

Have a fresh tip? Share with Coderwall community!

Post
Post a tip
Did you know?

JavaScript on a page runs with the privileges of that origin. One altered library, tag manager, or snippet can read inputs, change what people see, and call your APIs as the user.

Security insights from Cside