log with dump
by J. Jones
HTML
<button id='foo' onclick='clearConsole();'>clear console</button>
<div id="console">console log type thing</div>
<p>
JavaScript
function clearConsole() {
$('#console').html(" ");
}
function log(msg) {
var oldmsg = $('#console').html();
var newmsg = msg + "<br>" + oldmsg;
$('#console').html(newmsg);
}
function dump(object) {
var output = object + "<br>";
var keys = [];
for (var key in object) {
if (key.length > 0) keys.push(key);
}
keys.sort();
for (var i = 0; i < keys.length; i++) {
var property = keys[i];
try {
var val = object[property];
var vals = '' + val;
if (val !== null && val !== undefined && vals.length > 0) output += "key:" + property + ': value:' + object[property] + ';<br>';
} catch (err) { // deprecated members will cause this
//output += property + ': ' + err.message;
}
}
return output;
}