Skip to content

Instantly share code, notes, and snippets.

@Tiller
Forked from 140bytes/LICENSE.txt
Created June 5, 2011 18:12
Show Gist options
  • Save Tiller/1009237 to your computer and use it in GitHub Desktop.
Save Tiller/1009237 to your computer and use it in GitHub Desktop.
140byt.es -- YET ANOTHER DOM BUILDER §
var create = function(e,b,i){
e=document.createElement(e); // Create the HTML element. e(e) => /body/(/body/) => [body] => body
for(i in b)e[i]=b[i]; // Apply all the gived-attributes
return function(){ // function to append childs
for(i=0;b=arguments[i++];) // lists every childs
e.appendChild(b); // and appends them
return e // then, return the DOM element
}
};
function(e,b,i){e=document.createElement(e);for(i in b)e[i]=b[i];return function(){for(i=0;b=arguments[i++];)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": "YetAnotherDomBuilder",
"description": "This DomBuilder ALSO builds a dom ! But it ALSO takes attributes in argument §",
"keywords": [
"dom",
"dombuilder",
"dom builder"
]
}
<!DOCTYPE html>
<html>
<head>
<title>AGAIN AND AGAIN AND AGAIN AND AGAIN</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);for(i in b)e[i]=b[i];return function(){for(i=0;b=arguments[i++];)e.appendChild(b);return e}};
document.getElementById("ret").appendChild(
create('DIV', {align: 'center', innerHTML: 'Trololo<br/>'})(
create('UL', {id: 'ul'})(
create('LI', {innerHTML: 'This is the 1st li !'})(),
create('LI')(
create('UL')(
create('LI', {innerHTML: 'A 2nd level li !'})(),
create('LI', {innerHTML: 'And another one !'})()
)
)
),
create('SPAN')(document.createTextNode('Thanks you <3')),
create('div')()
)
);
</script>
</body>
</html>
@Tiller
Copy link
Author

Tiller commented Aug 17, 2011

I changed it for Stings.

Regex are pretty, because in most text editor, the regex'coloration is different from the string'one, so it make the tree more readable :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment