Skip to content

Instantly share code, notes, and snippets.

@Tiller
Forked from 140bytes/LICENSE.txt
Created June 5, 2011 17:37
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Tiller/1009208 to your computer and use it in GitHub Desktop.
Save Tiller/1009208 to your computer and use it in GitHub Desktop.
140byt.es -- DOM Builder §
var create = function(e,b,i){ // e: regex that contrains the tag name;
// b: one argument of the 2nd function;
// i: Counter
e = document.createElement(e); // Create the element. e(e) for : /body/.exec(/body/) => ['body'] => 'body'
return function(){ // To append the childs
for (i=0;b=arguments[i++];) // List of childs
b[0] ? // If it's a string (I know, bad idea)
e.innerHTML+=b // Write the text
:
e.appendChild(b); // Else, append the element
return e; // Then, return the element
}
};
function(e,b,i){e=document.createElement(e);return function(){for(i=0;b=arguments[i++];)b[0]?e.innerHTML+=b:e.appendChild(b);return e}}
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
Version 2, December 2004
Copyright (C) 2011 YOUR_NAME_HERE <YOUR_URL_HERE>
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": "DaDomBuilder",
"description": "this domBuilder, BUILDS A DOM §",
"keywords": [
"dom",
"dombuilder",
"dom builder"
]
}
<!DOCTYPE html>
<html>
<head>
<title>Like a Foo</title>
</head>
<body>
<div id="ret"></div>
<script>
// write a small example that shows off the API for your example
// and tests it in one fell swoop.
var create = function(e,b,i){e=document.createElement(e);return function(){for(i=0;b=arguments[i++];)b[0]?e.innerHTML+=b:e.appendChild(b);return e}};
document.getElementById("ret").appendChild(
create('DIV')(
create('UL')(
create('LI')('This is the 1st li !'),
create('LI')(
create('UL')(
create('LI')('A 2nd level li !'),
create('LI')('And another one !')
)
)
),
create('SPAN')('Thanks ', 'you ', '<3'),
create('div')()
)
);
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment