chi-create
DOM node creation ... now with added easy!
This module uses Node.js-style modules, for best results use browserify.
Examples
Create an empty <div>
node and append it to the document body:
var create = ; var node = ;documentbody;
Declare attributes on the node:
;
Add text to the node (treats strings as text, not HTML):
;
Add existing DOM nodes (automatically detects DOM nodes):
var span = ;;
Add lots of nodes (can handle nested arrays and variadic arguments):
var children = ; var mark = ; ;
Use them all together! Creates
<div class="hello"><span>Hello</span> World<strong>!</strong></div>
.
var hello = mark = attributes = 'class': 'hello' ; ;
Reference
;
tagName
is the HTML tag name (e.g. 'div'). contents
can be any number of
arguments where each argument is either a plain object (for attributes), a
string (for text), a DOM node (for adding existing DOM nodes), or an array
that contains DOM nodes or more arrays.