@mojule/h
TypeScript icon, indicating that this package has built-in type declarations

0.2.7 • Public • Published

h

API for creating DOM nodes, like hyperscript

npm install @mojule/h

const H = require( '@mojule/h' )

// window.document, JSDOM document instance, etc
const h = H( document )

const { element, textNode, comment, documentFragment, div, p } = h

const dom = div(
  p(
    {
      id: 'foo',
      click: e => console.log( 'clicked #foo' ),
      data: {
        fooBar: 'baz'
      },
      style: {
        fontSize: '16px',
        'font-weight': 'bold'
      }
    },
    documentFragment(
      element( 'custom-tag', 'hello' ),
      // text node as string literal
      ' ',
      // or explicitly
      textNode( 'world' ),
      comment( 'bar' )
    )
  )
)

// <p id="foo" data-foo-bar="baz" style="font-size: 16px; font-weight: bold;"><custom-tag>hello</custom-tag> world<!--bar--></p>
console.log( dom.innerHTML )

Readme

Keywords

none

Package Sidebar

Install

npm i @mojule/h

Weekly Downloads

2

Version

0.2.7

License

MIT

Unpacked Size

21.9 kB

Total Files

8

Last publish

Collaborators

  • andybell
  • nrkn