Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

ga-setattributes

germania7MIT1.1.0

Set attributes on DOM elements. Supports styles and HTML for convenience.

readme

ga-setattributes

Node/CommonJS/AMD module and global function for setting attribute values on DOM elements.

Installation

npm install ga-setattributes --save

Usage

The script checks for each attribute if it is in the element already, i.e. if it is native. Otherwise element.setAttribute will be used – except for style and html which get a special treatment.

// Require
var setAttributes = require('ga-setattributes');

// Pass element and attributes literal
setAttributes(targetObject, {
    class: "foo bar",
    alt: "An image"
});

Removing attributes

Just pass null on an attribute you want to remove. Internally, element.removeAttribute will be used.

setAttributes(targetObject, {
    class: null
});

Styles and HTML

setAttributes(targetObject, {
    html: "Click me",
    style: {
        color: "red"
    }
});

Develop with Gulp

Use Git Flow, always work in develop branch.

  • Install development dependencies: npm install
  • Run gulp watch
  • Work in src/

Builds are now in dist/