@thrillworksinc/dom
v1.0.2
Published
A collection of useful DOM interaction functions.
Downloads
2
Keywords
Readme
dom
A collection of useful DOM interaction functions.
Usage
import { getElement, getElements, createElement, append } from '@thrillworksinc/dom';
// Query and loop through elements
getElements('.hide-me').forEach(element => {
element.style.display = 'none';
});
// Create and append elements
const parent = getElement('.container');
const child = createElement('a', { href: '#', className: 'my-cool-anchor' }, "Click me!");
append(parent, child);
// Query an element with a parent context
getElement('.my-cool-anchor', parent);
Functions
| Name | Description | Arguments | |:--------------|:----------------------------------|:--------------------------| | getElement | Gets an individual element | selector, context | | getElements | Gets an array of elements | selector, context | | createElement | Creates an element | tagName, attrs, innerHTML | | getChildren | Get all child nodes of an element | element | | empty | Empties an element of child nodes | element | | fill | Fills an element with child nodes | element, ...children | | append | Appends one element to another | parent, child | | prepend | Prepends one element to another | parent, child |