1.0.3 • Published 4 years ago

select-el v1.0.3

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

DOM Elements Selectors

This module allows you to get elements by CSS selectors. The advantage of the module is that it recognizes what input selector you use - either a string or a DOM element. It may be very useful when you are not sure what a variable is: wether a string selector or an element.

How to start

npm install select-el

Example

import * as selectEl from 'select-el';
// or
// var selectEl = require('select-el');

// get an element
selectEl.one(".my-selector");
// get all elements
selectEl.all(".my-selector");
// check if a variable is an element
selectEl.isElement(".my-selector");
// check if an element exists
selectEl.exists(".my-selector");
// check if a variable is an HTML Element
selectEl.isHTMLElement(".my-selector");
// check if a variable is Window
selectEl.isWindow(selector);
// select elements from an existing array
selectEl.selectElements([
    false,
    document.querySelector("li")
])

Functions

selectEl.one

Select only one element.

ArgumentTypeOptionalDescription
selector(HTMLElement | Window | string)Either a string selector or an element.
outerstring|HTMLElementyesAn outer element. Either a string selector or an element. Relevant only for string selectors.

Returns (HTMLElement | null)

selectEl.all

Select all elements.

ArgumentTypeOptionalDescription
selector(NodeList | Array<HTMLElement|Window> | HTMLElement | Window | string)A string selector, an element or a node list.
outerstring|HTMLElementyesAn outer element. Either a string selector or an element.

Returns NodeList | Array<HTMLElement|Window>

selectEl.exists

Check if an element exists.

ArgumentTypeOptionalDescription
selector(HTMLElement | string)A string selector or an element.

Returns boolean

selectEl.isElement

Check if variable is an HTMLElement or Window.

ArgumentTypeOptionalDescription
el(any)The variable to be checked.

Returns boolean

selectEl.isHTMLElement

Check if variable is an HTMLElement.

ArgumentTypeOptionalDescription
el(any)The variable to be checked.

Returns boolean

selectEl.isWindow

Check if variable is Window.

ArgumentTypeOptionalDescription
el(any)The variable to be checked.

Returns boolean

selectEl.selectElements

Select elements in array.

ArgumentTypeOptionalDescription
array(Array | NodeList)An array of elements.

Returns NodeList