ampersand-dom
Minimal util-layer for applying transformations to DOM.
It's a pretty thin layer on top of DOM APIs.
It has zero dependencies.
install
npm install ampersand-dom
browser support
falsy values
When setting something to a falsy value: NaN
, undefined
, null
, and false
all become ''
. However, 0
becomes "0"
in order to allow setting 0
as the text content of an element.
example
Here are all the methods and their usage:
var dom = require('ampersand-dom');
dom.text(el, 'set text content');
dom.addClass(el, 'someclass');
dom.hasClass(el, 'someclass');
dom.removeClass(el, 'someclass');
dom.switchClass(el, 'oldclass', 'newclass');
dom.addAttribute(el, 'checked');
dom.removeAttribute(el, 'checked');
dom.setAttribute(el, 'value', 'the value');
dom.hide(el);
dom.show(el);
dom.html(el, '<div></div>');
credits
Initially created by @HenrikJoreteg with much inspiration/discussion with @philip_roberts.
license
MIT