1. bianco.attr
Helper to set/get/remove DOM attributes on a list of nodes
bianco.attr
Package: bianco.attr
Created by: biancojs
Last modified: Mon, 13 Jun 2022 04:35:18 GMT
Version: 1.1.1
License: MIT
Downloads: 2,196
Repository: git+https://github.com/biancojs/@.git

Install

npm install bianco.attr
yarn add bianco.attr

bianco.attr

Build Status
NPM version
NPM downloads
MIT License

Usage

 import { set, get, has, remove } from 'bianco.attr'

// set an attribute on a node
const img = document.createElement('img')

set(img, 'width', 100)
get(img, 'width') // => '100'
has(img, 'width') // => true

remove(img, 'width')
get(img, 'width') // => null

API

Table of Contents

set

Set any attribute on a single or a list of DOM nodes

Parameters

  • els (HTMLElement | NodeList | Array) DOM node/s to parse
  • name (string | Object) either the name of the attribute to set
    or a list of properties as object key - value
  • value string the new value of the attribute (optional)

Examples

 import { set } from 'bianco.attr'

const img = document.createElement('img')

set(img, 'width', 100)

// or also
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') // => '200'

// or also
get(img, ['width', 'height']) // => ['200', '300']

// or also
get([img1, img2], ['width', 'height']) // => [['200', '300'], ['500', '200']]

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 the width attribute

// or also
remove(img, ['width', 'height']) // remove the width and the height attribute

// or also
remove([img1, img2], ['width', 'height']) // remove the width and the height attribute from both images

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') // false

// or also
has(img, ['width', 'height']) // => [false, false]

// or also
has([img1, img2], ['width', 'height']) // => [[false, false], [false, false]]

Returns (boolean | Array) true or false or an array of boolean values

RELATED POST

10 Must-Know Windows Shortcuts That Will Save You Time

10 Must-Know Windows Shortcuts That Will Save You Time

Arrays vs Linked Lists: Which is Better for Memory Management in Data Structures?

Arrays vs Linked Lists: Which is Better for Memory Management in Data Structures?

Navigating AWS Networking: Essential Hacks for Smooth Operation

Navigating AWS Networking: Essential Hacks for Smooth Operation

Achieving Stunning Visuals with Unity's Global Illumination

Achieving Stunning Visuals with Unity's Global Illumination

Nim's Hidden Gems: Lesser-known Features for Writing Efficient Code

Nim's Hidden Gems: Lesser-known Features for Writing Efficient Code