bianco.attr
Usage
import { set, get, has, remove } from 'bianco.attr'
const img = document.createElement('img')
set(img, 'width', 100)
get(img, 'width')
has(img, 'width')
remove(img, 'width')
get(img, 'width')
API
set
Set any attribute on a single or a list of DOM nodes
Parameters
els
(HTMLElement | NodeList | Array) DOM node/s to parsename
(String | Object) either the name of the attribute to set
or a list of properties as object key - valuevalue
String the new value of the attribute (optional)
Examples
import { set } from 'bianco.attr'
const img = document.createElement('img')
set(img, 'width', 100)
set(img, {
width: 300,
height: 300
})
Returns (HTMLElement | NodeList | Array) the original array of elements passed to this function
get
Get any attribute from a single or a list of DOM nodes
Parameters
Examples
import { get } from 'bianco.attr'
const img = document.createElement('img')
get(img, 'width')
get(img, ['width', 'height'])
get([img1, img2], ['width', 'height'])
Returns (Array | String) list of the attributes found
remove
Remove any attribute from a single or a list of DOM nodes
Parameters
Examples
import { remove } from 'bianco.attr'
remove(img, 'width')
remove(img, ['width', 'height'])
remove([img1, img2], ['width', 'height'])
Returns (HTMLElement | NodeList | Array) the original array of elements passed to this function
has
Set any attribute on a single or a list of DOM nodes
Parameters
Examples
import { has } from 'bianco.attr'
has(img, 'width')
has(img, ['width', 'height'])
has([img1, img2], ['width', 'height'])
Returns (Boolean | Array) true or false or an array of boolean values