Skip to content

Instantly share code, notes, and snippets.

@superlinkx
Last active June 14, 2022 16:31
Show Gist options
  • Save superlinkx/5578803 to your computer and use it in GitHub Desktop.
Save superlinkx/5578803 to your computer and use it in GitHub Desktop.
Simple debugging console for JavaScript that you can embed in your debugging html. Use html.log(<message>) in your javascript to output to this console. The style can be modified easily to your liking.
<!DOCTYPE html>
<html>
<head>
<style>
#console {
width: 800px;
height: 400px;
background: #575757;
color: white;
margin: 30px auto;
padding: 10px;
overflow: auto;
}
</style>
<script>
$(function(){
html = {
panel: $("#console"),
log: function(m) {
this.panel.append("<div>&gt; "+m+"</div>");
}
};
});
</script>
</head>
<body>
<div id="console"></div>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<style>
#console {
width: 800px;
height: 400px;
background: #575757;
color: white;
margin: 30px auto;
padding: 10px;
overflow: auto;
}
</style>
<script>
document.addEventListener("DOMContentLoaded", function(){
html = {
panel: document.querySelector("#console"),
log: function(m) {
var newline = document.createElement("div");
newline.innerHTML = "&gt; " + m;
this.panel.appendChild(newline);
}
};
});
</script>
</head>
<body>
<div id="console"></div>
</body>
</html>
@superlinkx
Copy link
Author

The jQuery and non-jQuery versions are similar to use. I have the non-jQuery version for those who aren't using jQuery or don't want any extra libraries in their code.

@superlinkx
Copy link
Author

Got rid of deprecated window.onload syntax thanks to rlifshay. Also changed > to html entity for proper syntax.

@superlinkx
Copy link
Author

Added overflow: auto. Realized that it wouldn't scroll before, so this should fix it, though it's a bit ugly. I might make a simple css scrollbar later to make it look nicer.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment