domgen
v1.0.2
Published
domgen is tiny and intelligent DOM generating helper.
Downloads
30
Readme
domgen
domgen is tiny and intelligent DOM generating helper.
Install
npm install --save domgen
Usage
The domgen signature is:
domgen(elementName, attributes, children)
Examples:
// simple example
document.body.appendChild(
domgen('p', {style:'color:orange;'}, 'Text')
)
// Natural notation for class and sytle attributes.
// Ofcourse you can also write like this: class: 'classA classB'
document.body.appendChild(
domgen('p', {class:['classA', 'classB']}, 'Text have class')
)
document.body.appendChild(
domgen('p', {style:{'color': 'green'}}, 'Text have style')
)
// You can set children recursively.
document.body.appendChild(
domgen('p', null, [domgen('span', null, 'Child Element Text Node')])
)
// Array notation
document.body.appendChild(
domgen('p', null, [['span', null, 'Generated by array notation.']])
)
// Event
function onClickButton () {
alert('click!')
}
document.body.appendChild(
domgen('button', {onclick: onClickButton}, 'Click Me')
)
License
MIT