node package manager


generate HTML from javascript the easy way.


generate HTML from javascript the easy way.

      h('h1.classy', 'h')),
    h('div#menu', { style: { float: 'left', width: '200px' } },
        h('li', 'one'),
        h('li', 'two'),
        h('li', 'three'))),
    h('div#content', {style: {float: 'left'} },
      h('h2', 'content title'),
        "so it's just like a templating engine,\n",
        "but easy to use inline with javascript\n"),
        "the intension is for this to be used to create\n",
        "reusable, interactive html widgets. ")))

Create an HTMLElement. first argument must be the tag name.

If the tag name is of form name.class1.class2#id that is a short cut for setting the class and id.

If an {} object is passed in, it's values will be used to set attributes.

h('a', {href: ''}, 'h')

If an attribute is a function, then it will be registered as an event listener.

h('a', {href: '#', click: function () {
  alert('you are 1,000,000th visitor!'
  return false

If an attribute has a style property, then that will be handled specially.

h('', {style: {font: 'comic sans MS'}}, 'happy birthday!')

You may pass in attributes in multiple positions, it's no problem!

If an argument is a string, a TextNode is created in that position.

If a argument is a HTMLELement, for example, the return value of a call to h thats cool too.

This is just ignored.

Each item in the array is treated like a ordinary child. (string or HTMLElement) this is uesful when you want to iterate over an object:

  Object.keys(obj).map(function (k) {
    return h('tr'
      h('th', k),
      h('td', obj[k])