Socket
Socket
Sign inDemoInstall

domutil

Package Overview
Dependencies
2
Maintainers
1
Versions
29
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    domutil

DOM utility functions


Version published
Weekly downloads
13
increased by18.18%
Maintainers
1
Install size
552 kB
Created
Weekly downloads
 

Readme

Source

domutil

Simple standalone DOM utility functions, mostly ripped from jQuery.

Installation

Browserify recommended.

$ npm install domutil

In the codes:

var du = require('domutil');

API

Classes

du.hasClass(el, className)
du.addClass(el, className)
du.removeClass(el, className)
du.toggleClass(el, className)
du.removeMatchingClasses(el, regexp)

Remove all classes on element that match regexp.

Events

du.bind(el, evtType, cb, [useCapture])
du.bind_c(el, evtType, cb, [useCapture])

As above, but returns a cancellation function.

du.delegate(el, evtType, selector, cb, [useCapture])
du.delegate_c(el, evtType, selector, cb, [useCapture])

As above, but returns a cancellation function.

du.unbind(el, evtType, cb, [useCapture])
du.stop(evt)

Shortcut for:

evt.preventDefault();
evt.stopPropagation();

Layout

du.setRect(el, x, y, width, height)

Shortcut for:

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

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.

du.isVisible(el)

Inverse of du.isHidden(el).

Matches Selector

du.matchesSelector(selector, el)

Node

du.append(el, content)

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

du.clear(el)

Remove all child nodes of el.

du.isElement(thing)
du.replace(oldEl, newEl)

Replace oldEl with newEl.

du.content(el, content)

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

Style

du.style(el, attribute, value)

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

du.style(el, attributes)

Assign all key/value pairs of attributes to el.style.

du.removeStyle(el, attribute)

Remove style attribute from el.

Text

du.getText(el)
du.text(el, text)

Viewport

du.viewportSize()

Keywords

FAQs

Last updated on 09 Sep 2014

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc