domgen

1.0.2 • Public • Published

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

Dependencies (0)

    Dev Dependencies (1)

    Package Sidebar

    Install

    npm i domgen

    Weekly Downloads

    1

    Version

    1.0.2

    License

    MIT

    Last publish

    Collaborators

    • devneko