Skip to content

Commit b55a6f3

Browse files
committed
Add the ability to specify a tag
1 parent 89329fc commit b55a6f3

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

snippet.js

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,20 @@
11
// MIT license, see: https://github.com/tjcrowder/simple-snippets-console/blob/master/LICENSE
22
var snippet = {
3-
version: "1.0",
3+
version: "1.1",
44

55
// Writes out the given text in a monospaced paragraph tag, escaping
66
// & and < so they aren't rendered as HTML.
7-
log: function(msg) {
7+
log: function(msg, tag) {
8+
var elm = document.createElement(tag || "p");
9+
elm.style.fontFamily = "monospace";
10+
elm.style.margin = "2px 0 2px 0";
811
if (Object.prototype.toString.call(msg) === "[object Array]") {
912
msg = msg.join();
1013
} else if (typeof object === "object") {
1114
msg = msg === null ? "null" : JSON.stringify(msg);
1215
}
13-
document.body.insertAdjacentHTML(
14-
'beforeend',
15-
'<p style="font-family: monospace; margin: 2px 0 2px 0">' +
16-
msg.replace(/&/g, '&amp;').replace(/</g, '&lt;') +
17-
'</p>'
18-
);
16+
elm.innerHTML = msg.replace(/&/g, '&amp;').replace(/</g, '&lt;');
17+
document.body.appendChild(elm);
1918
},
2019

2120
// Writes out the given HTML at the end of the body,

0 commit comments

Comments
 (0)