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 :: schema knex.js 
Javascript :: how to update react app 
Javascript :: how to use private github repo as npm dependency 
Javascript :: bootstrap pop modal from another modal 
Javascript :: mongodb mongoose update delete key 
Javascript :: discord js check every x minutes 
Javascript :: js get dropdown value 
Javascript :: display json data in html table react 
Javascript :: how to print json.stringify of nested objects 
Javascript :: faire un tableau en javascript 
Javascript :: javascript allow only numbers in input alert 
Javascript :: how to access ::after Pseudo-Elements from javascript 
Javascript :: remove element javascript 
Javascript :: javascript fade color 
Javascript :: FTP download local file 
Javascript :: array.sort 
Javascript :: escape character javascript 
Javascript :: new function in javascript 
Javascript :: blockchain javascript 
Javascript :: emailjs react 
Javascript :: window frames js 
Javascript :: remove first character javascript 
Javascript :: utc clock 
Javascript :: get all recod from db nodejs mongodb 
Javascript :: calling javascript from java 
Javascript :: save to local storage 
Javascript :: array indexof 
Javascript :: react functional component 
Javascript :: shopify image pciker 
Javascript :: check the type of a variable in js 
ADD CONTENT
Topic
Content
Source link
Name
7+7 =