Skip to content

Instantly share code, notes, and snippets.

@Quby
Forked from 140bytes/LICENSE.txt
Created July 30, 2011 16:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Quby/1115717 to your computer and use it in GitHub Desktop.
Save Quby/1115717 to your computer and use it in GitHub Desktop.
140byt.es -- Click ↑↑ fork ↑↑ to play!
function domBuilder(args, tag, node, attr, temp, level) {
node=document.createElement((tag = args.shift(args.pop()))[0]); //Creating node
for (attr in tag[1]) {
node[attr] = tag[1][attr]; //Set attributes
}
tag = []; //Accumulator
level = 0;
args[1] || (node.innerHTML = args, args = tag); //If innerHTML
for (attr in args) {
tag.push(temp = args[attr]);
temp.split || (
temp[0] ? level++ : --level || (
node.appendChild( domBuilder(tag) ),
tag = []
)
)
}
return node;
};
function domBuilder(a,b,c,d,e,f){c=document.createElement((b=a.shift(a.pop()))[0]);for(d in b[1])c[d]=b[1][d];b=[],f=0,a[1]||(c.innerHTML=a,a=b);for(d in a)b.push(e=a[d]),e.split||(e[0]?f++:--f||(c.appendChild(domBuilder(b)),b=[]));return c}
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
Version 2, December 2004
Copyright (C) 2011 Quby <art543484 at ya.ru>
Everyone is permitted to copy and distribute verbatim or modified
copies of this license document, and changing it is allowed as long
as the name is changed.
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
0. You just DO WHAT THE FUCK YOU WANT TO.
{
"name": "domBuilder in 241 bytes",
"description": "domBuilder in 241 bytes.",
"keywords": [
"dom",
"domBuilder"
]
}
<!DOCTYPE html>
<title>Foo</title>
<div>Expected value: <b>undefined</b></div>
<div>Actual value: <b id="ret"></b></div>
<script>
function domBuilder(a,b,c,d,e,f){c=document.createElement((b=a.shift(a.pop()))[0]);for(d in b[1])c[d]=b[1][d];b=[],f=0,a[1]||(c.innerHTML=a,a=b);for(d in a)b.push(e=a[d]),e.split||(e[0]?f++:--f||(c.appendChild(domBuilder(b)),b=[]));return c}
document.body.appendChild(domBuilder([
["div"],
["div"],
["textarea"],
[],
[],
["input"],
[],
["p"],
"test",
[],
[]
]));
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment