Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

display console log in HTML

(function () {
    var old = console.log;
    var logger = document.getElementById('log');
    console.log = function (message) {
        if (typeof message == 'object') {
            logger.innerHTML += (JSON && JSON.stringify ? JSON.stringify(message) : message) + '<br />';
        } else {
            logger.innerHTML += message + '<br />';
        }
    }
})();
Comment

console log on html

(function (logger) {
    console.old = console.log;
    console.log = function () {
        var output = "", arg, i;

        for (i = 0; i < arguments.length; i++) {
            arg = arguments[i];
            output += "<span class="log-" + (typeof arg) + "">";

            if (
                typeof arg === "object" &&
                typeof JSON === "object" &&
                typeof JSON.stringify === "function"
            ) {
                output += JSON.stringify(arg);   
            } else {
                output += arg;   
            }

            output += "</span>&nbsp;";
        }

        logger.innerHTML += output + "<br>";
        console.old.apply(undefined, arguments);
    };
})(document.getElementById("logger"));

// Testing
console.log("Hi!", {a:3, b:6}, 42, true);
console.log("Multiple", "arguments", "here");
console.log(null, undefined);
console.old("Eyy, that's the old and boring one.");
Comment

PREVIOUS NEXT
Code Example
Javascript :: how to download file from link in react 
Javascript :: generate express js project 
Javascript :: how to take screenshot of desktop using electron js 
Javascript :: call a function multiple times 
Javascript :: async awiat 
Javascript :: download images from http link in react 
Javascript :: jquerry in bootstrap 
Javascript :: mongodb sort 
Javascript :: vue get if checkbox is checked 
Javascript :: tsconfig 
Javascript :: select elements of an array starting by a certain letter javascript 
Javascript :: header disallowed by preflight response in express 
Javascript :: convert a new date standard to a yyy-mm-dd format in javascript 
Javascript :: parse time in javascript 
Javascript :: normalize javascript 
Javascript :: js console log multiple 
Javascript :: how to insert an item into an array at a specific index javascript 
Javascript :: object.entries 
Javascript :: char array to string javascript 
Javascript :: usereducer react js 
Javascript :: vuejs get value of checkbox group 
Javascript :: send x-www-form-urlencoded request nodejs 
Javascript :: reactjs dynamic route 
Javascript :: how to appendChild in the begin of the div javascript 
Javascript :: canvas rectangle rounded corners 
Javascript :: angular hostlistener 
Javascript :: parse string to int nodejs 
Javascript :: filter duplicates multidimensional array javascript 
Javascript :: how to add json file to mongodb 
Javascript :: promise.race polyfill 
ADD CONTENT
Topic
Content
Source link
Name
8+5 =