Latest commit 947ecf9 Apr 21, 2016
Failed to load latest commit information.
test Corrected test case to allow undefined values for inputs Mar 10, 2016 Fix typo Apr 19, 2016
index.js Throw errors when passing invalid input values Mar 10, 2016
parse-tag.js Add support for non-ASCII characters in virtual-hyperscript tags May 31, 2015


A DSL for creating virtual trees


var h = require('virtual-dom/h')

var tree = h('', [
    h('span', 'some text'),
    h('input', { type: 'text', value: 'foo' })


See hyperscript which has the same interface.

Except virtual-hyperscript returns a virtual DOM tree instead of a DOM element.

h(selector, properties, children)

h() takes a selector, an optional properties object and an optional array of children or a child that is a string.

If you pass it a selector like it will parse the selector and change the id and className properties of the properties object.

If you pass it an array of children it will have child nodes, normally you want to create children with h().

If you pass it a string it will create an array containing a single child node that is a text element.

Special properties in h()


If you call h with h('div', { key: someKey }) it will set a key on the return VNode. This key is not a normal DOM property but is a virtual-dom optimization hint.

It basically tells virtual-dom to re-order DOM nodes instead of mutating them.


If you call h with h('div', { namespace: "" }) it will set the namespace on the returned VNode. This namespace is not a normal DOM property, instead it will cause vdom to create a DOM element with a namespace.


Note: You must create an instance of dom-delegator for ev-* to work.

If you call h with h('div', { ev-click: function (ev) { } }) it will store the event handler on the dom element. It will not set a property 'ev-foo' on the DOM element.

This means that dom-delegator will recognise the event handler on that element and correctly call your handler when a click event happens.


npm install virtual-dom


  • Raynos
  • Matt Esch

MIT Licenced