meduzen / setAttributes

call .setAttribute on a DOM node more easily

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

setAttributes

Set and delete multiple attributes in a DOM element.

This...

const el = document.querySelector("input");

el.setAttribute("type", "password");
el.setAttribute("name", "password-field");
el.removeAttribute("maxlength");

...is equivalent to this:

const setAttributes = require("setattributes");

const el = document.querySelector("input");

setAttributes(el, {
  type: "password",
  name: "password-field",
  maxlength: null,
});

Installation

npm install setattributes

Then, to import it:

import setAttributes from "setattributes";

About

call .setAttribute on a DOM node more easily

License:The Unlicense


Languages

Language:JavaScript 100.0%