alekseenkodev
3/26/2018 - 8:40 PM

generate random elem with code

generate random elem with code


    
        var custom_elems = ['span','div','p','ul','li'];
        var rand = custom_elems[Math.floor(Math.random()*custom_elems.length)];

        var para = document.createElement(rand);
        para.style.display = "none";
        var str = randomString(12);
        
        para.classList.add(randomString(12));
        var node = document.createTextNode(randomString(88));
para.appendChild(node);
        var element = document.getElementById("app");
        element.appendChild(para);




    function randomString(length) {
    var text = "";
    var possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
        for(var i = 0; i < length; i++) {
        text += possible.charAt(Math.floor(Math.random() * possible.length));
        }
        return text;
    }