Skip to content

Instantly share code, notes, and snippets.

@scytacki
Created November 18, 2011 17:06
Show Gist options
  • Save scytacki/1377062 to your computer and use it in GitHub Desktop.
Save scytacki/1377062 to your computer and use it in GitHub Desktop.
innerHTML test
<html>
<head>
<script>
var tagSoup = [
"A", "<B>1<\/B>",
"ABBR", "<B>1<\/B>",
"ACRONYM", "<B>1<\/B>",
"ADDRESS", "<B>1<\/B>",
"APPLET", "<B>1<\/B>",
"B", "<B>1<\/B>",
"BASE", "<B>1<\/B>",
"BASEFONT", "<B>1<\/B>",
"BDO", "<B>1<\/B>",
"BIG", "<B>1<\/B>",
"BLOCKQUOTE", "<B>1<\/B>",
"BODY", "<B>1<\/B>",
"BUTTON", "<B>1<\/B>",
"CAPTION", "<B>1<\/B>",
"CENTER", "<B>1<\/B>",
"CITE", "<B>1<\/B>",
"CODE", "<B>1<\/B>",
"COLGROUP", "<COL WIDTH=\"10\">",
"DD", "<B>1<\/B>",
"DEL", "<B>1<\/B>",
"DFN", "<B>1<\/B>",
"DIR", "<B>1<\/B>",
"DIV", "<B>1<\/B>",
"DL", "<DT>1<\/DT>",
"DT", "<B>1<\/B>",
"EM", "<B>1<\/B>",
"FIELDSET", "<B>1<\/B>",
"FONT", "<B>1<\/B>",
"FORM", "<B>1<\/B>",
"H1", "<B>1<\/B>",
"H2", "<B>1<\/B>",
"H3", "<B>1<\/B>",
"H4", "<B>1<\/B>",
"H5", "<B>1<\/B>",
"H6", "<B>1<\/B>",
"HEAD", "<STYLE>1<\/STYLE>",
"HTML", "<BODY><\/BODY>",
"I", "<B>1<\/B>",
"INS", "<B>1<\/B>",
"ISINDEX", "<B>1<\/B>",
"KBD", "<B>1<\/B>",
"LABEL", "<B>1<\/B>",
"LEGEND", "<B>1<\/B>",
"LI", "<B>1<\/B>",
"MAP", "<AREA COORDS=\"0,0,1,1\" HREF=foo SHAPE=rect>",
"MENU", "<LI>1<\/LI>",
"NOFRAMES", "<B>1<\/B>",
"NOSCRIPT", "<B>1<\/B>",
"OBJECT", "<PARAM NAME=\"FOO\" VALUE=\"1\">",
"OL", "<LI>1<\/Li>",
"OPTGROUP", "<OPTION>1</OPTION>",
"OPTION", "<B>1<\/B>",
"P", "<B>1<\/B>",
"PRE", "<B>1<\/B>",
"Q", "<B>1<\/B>",
"S", "<B>1<\/B>",
"SAMP", "<B>1<\/B>",
"SCRIPT", "1+1",
"SELECT", "<OPTION>1</OPTION>",
"SMALL", "<B>1<\/B>",
"SPAN", "<B>1<\/B>",
"STRIKE", "<B>1<\/B>",
"STRONG", "<B>1<\/B>",
"STYLE", "p { color: pink }",
"SUB", "<B>1<\/B>",
"SUP", "<B>1<\/B>",
"TABLE", "<TR><TD>1<\/TD><\/TR>",
"TBODY", "<TR><TD>1<\/TD><\/TR>",
"TD", "<B>1<\/B>",
"TEXTAREA", "&lt;B&gt;1&lt;/B&gt;",
"TFOOT", "<TR><TD>1<\/TD><\/TR>",
"TH", "<B>1<\/B>",
"THEAD", "<TR><TD>1<\/TD><\/TR>",
"TITLE", "&lt;B&gt;1&lt;/B&gt;",
"TR", "<TD>1<\/TD>",
"TT", "<B>1<\/B>",
"U", "<B>1<\/B>",
"UL", "<LI>1<\/LI>",
"VAR", "<B>1<\/B>"
];
</script>
</head>
<body>
<script>(function () {
var logList = document.createElement('ul');
document.body.appendChild(logList);
function log(msg) {
var li = document.createElement('li');
logList.appendChild(li);
li.appendChild(document.createTextNode(msg))
}
for (var i = 0, n = tagSoup.length; i < n;) {
var tagName = tagSoup[i++];
var html = tagSoup[i++];
var el;
try {
el = document.createElement(tagName);
} catch (ex) {
log('Cannot create ' + tagName + ' : ' + ex);
continue;
}
try {
el.innerHTML = html;
} catch (ex) {
log('Cannot set innerHTML of ' + tagName + ' : ' + ex);
continue;
}
}
log('done');
})();</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment