Skip to content

Instantly share code, notes, and snippets.

@howardr
Created May 13, 2010 20:50
Show Gist options
  • Save howardr/400440 to your computer and use it in GitHub Desktop.
Save howardr/400440 to your computer and use it in GitHub Desktop.
/*
* Create an element on page that outputs info you pass it. I use it for IE6 testing
* Returns a unique element, and also overwrites console.log. Optionally you can pass in an id
* of an element for which to insert the debug element instead of document body.
*
* Usage:
* var debug = createDebugElement();
* debug.innerHTML = 'show my message';
*
* console.log('show my message');
*/
function createDebugElement(within_id) {
var debug = document.createElement('div');
var within = within_id ? document.getElementById(within_id) : document.body;
// inserting debug element as first child of given element or body
within.insertBefore(debug, within.firstChild);
// override console.log to use the element
if(!window.console) {
window.console = {};
}
window.console.log = function(message) {
debug.innerHTML = message;
}
return debug;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment