Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

bianco.attr

Package Overview
Dependencies
Maintainers
3
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

bianco.attr

Helper to set/get/remove DOM attributes on a list of nodes

  • 0.0.5
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
542
decreased by-13.42%
Maintainers
3
Weekly downloads
 
Created
Source

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

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

Keywords

FAQs

Package last updated on 03 Jun 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc