DOM utility functions


Simple standalone DOM utility functions, mostly ripped from jQuery.

Browserify recommended.

$ npm install domutil

In the codes:

var du = require('domutil');

Remove all classes on element that match regexp.

As above, but returns a cancellation function.

As above, but returns a cancellation function.

Shortcut for:


Shortcut for:

du.setPosition(el, x, y);
du.setSize(el, width, height);

Fast check for el.offsetWidth === 0 || el.offsetHeight === 0. This is the same test used by jQuery's :visible pseudo-selector.

This will detect elements that have been hidden directly with display: none or visibility: hidden. It also seems to work with elements whose ancestors have been hidden with display: none.

False positives will be reported for elements which have zero height or width.

Inverse of du.isHidden(el).

Append content to el. content may be a text string, HTML string, DOM node, DocumentFragment, or an array of the aforementioned.

Remove all child nodes of el.

Replace oldEl with newEl.

Set all children of el. Equivalent to du.clear(el); du.append(el, content).

Equivalent to[attribute] = value. If value is a number, px will be appended.

Assign all key/value pairs of attributes to

Remove style attribute from el.