Socket
Socket
Sign inDemoInstall

@braintree/class-list

Package Overview
Dependencies
0
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @braintree/class-list

A helper for applying classes to dom nodes.


Version published
Weekly downloads
82K
decreased by-8.87%
Maintainers
1
Install size
5.25 kB
Created
Weekly downloads
 

Readme

Source

classList

A helper module for adding and removing classes from DOM nodes in browsers that do not natively support the classList property on DOM nodes.

Installation

npm

npm install --save @braintree/class-list

This module uses commonjs. You must use a build tool such as Browserify or Webpack to include it in your frontend project.

Usage

var classList = require("@braintree/class-list");

add

Adds a class to specified DOM node.

var element = document.querySelector("#id");

element.className = "some-class";

classList.add(element, "any", "number", "of", "classes", "to", "add");

element.className === "some-class any number of classes to add";

remove

Removes a class to specified DOM node.

var element = document.querySelector("#id");

element.className = "some-class some-other-class another-class";

classList.remove(element, "some-class", "another-class");

element.className === "some-other-class";

toggle

Toggles a class to specified DOM node. The first argument is the DOM node, the second is the class to toggle, and the third argument is a boolean for whether to add the class or remove it.

var element = document.querySelector("#id");
var shouldAdd = function (className) {
  return element.className.indexOf(className) === -1;
};

element.className = "some-class some-other-class";

classList.toggle(element, "some-class", shouldAdd("some-class"));

element.className === "some-other-class";

classList.toggle(element, "some-class", shouldAdd("some-class"));

element.className === "some-class some-other-class";

Tests

npm test

FAQs

Last updated on 07 Nov 2023

Did you know?

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc