Skip to content

Instantly share code, notes, and snippets.

@kevinchisholm
Last active November 21, 2017 19:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kevinchisholm/b74dab0d32f53ac2d655266605cf7f2b to your computer and use it in GitHub Desktop.
Save kevinchisholm/b74dab0d32f53ac2d655266605cf7f2b to your computer and use it in GitHub Desktop.
Show console.log output in the DOM
(function () {
var $consoleLog = $('<div id="console-log"></div>'),
newLine = function(){return $('<p class="console-line"></p>'); },
cssText = '.console-line{margin:10px;padding:10px;background-color:#ededed;border:1px solid #ccc;font-weight:700;font-family:monospace;color:#333;font-size:18px}.dir{background-color:#80e5a6}.info{background-color:#cff}.warn{background-color:#fdfd96}.error{background-color:#ff6961}',
$style = $('<style>' + cssText + '</style>');
//reminder: jQuery is a dependency!
$('body').prepend($consoleLog);
$('body').append($style);
window.console = {
log: function(text) {
$consoleLog.append(newLine().html(text));
},
dir: function(text) {
$consoleLog.append(newLine().addClass('dir').html(JSON.stringify(text)));
},
info: function(text) {
$consoleLog.append(newLine().addClass('info').html(text));
},
warn: function(text) {
$consoleLog.append(newLine().addClass('warn').html(text));
},
error: function(text) {
$consoleLog.append(newLine().addClass('error').html(text));
},
};
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment