/dom-helper

Primary LanguageJavaScriptMIT LicenseMIT

DOM Helper

Helps with common DOM tasks

Live Demo

Installation

Use the package manager npm for installation.

$ npm install @deleteagency/dom-helper

Usage

import {createFragment, createElement} from  '@deleteagency/dom-helper';

const fragment = createFragment('<li>option 1</li><li>option 2</li>');
const newElement = createElement('<a href="google.com">Go to Google</a>');

API

createFragment(htmlString)

Creates a new DocumentFragment based on the provided markup

htmlString

Required
Type: String

DOMHelper.createElement(htmlString)

Creates a new Element based on the provided markup.
If markup contains more then 1 sibling elements, only first will be returned.
Returns null if markup contains zero valid elements.

htmlString

Required
Type: String

querySelectorParent(target, selector, includeSelf = false)

Searches element up the DOM tree that matches provided selector

target

Required
Type: Element

selector

Required
Type: string

includeSelf

Optional
Type: boolean

isElement(element)

Checks whether the passed value is an Element

element

Required
Type: Object

createEvent(name)

Creates new Event ready for dispatching

name

Required
Type: String

License

MIT