-
-
Save Quby/1115717 to your computer and use it in GitHub Desktop.
140byt.es -- Click ↑↑ fork ↑↑ to play!
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "domBuilder in 241 bytes", | |
"description": "domBuilder in 241 bytes.", | |
"keywords": [ | |
"dom", | |
"domBuilder" | |
] | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!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