0.3.0 • Published 4 years ago

@zimpa/dom v0.3.0

Weekly downloads
-
License
MIT
Repository
-
Last release
4 years ago

@zimpa/dom

Install

Install the package by running npm install --save @zimpa/dom.

Functions

$

The $ function is syntactic sugar for document.querySelector. The only difference is that if it doesn't find an element it will return undefined instead of null.

The type of the returned value is Element, if you prefer a more specific type that implements the `Element interface, you can provide it as a generic.

const input = $<HTMLInputElement>('input[type=text]');

$$

The $$ function is syntactic sugar for document.querySelectorAll. The only difference is that it will return an Array with found elements instead of a NodeList instance. The type of the values is Element. This can be overridden by supplying a generic.

const validLinks = $$<HTMLAnchorElement>('a[href]');

elementFromString

The elementFromString is able to create an element from an HTML string. This can be convenient when you get an HTML string from an API and want to create an element out of it.

const html = '<p>Some HTML</p>';
const element = elementFromString(html);

element.classList.add('some_class');
document.body.appendChild(element);
0.3.0

4 years ago

0.2.4

4 years ago

0.2.3

4 years ago

0.2.2

4 years ago

0.2.1

4 years ago

0.2.0

4 years ago

0.1.2

4 years ago

0.1.1

4 years ago

0.1.0

4 years ago