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

svg-classlist-polyfill

Package Overview
Dependencies
Maintainers
2
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

svg-classlist-polyfill

Polyfill for classList methods (contains, add, remove, toggle) on SVG elements.

  • 1.1.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
2
Created
Source

SVG classList Polyfill

Polyfill for classList methods (contains, add, remove, toggle) on SVG elements which aren't supported on IE11 and other older browsers.

Installation and Usage

npm install svg-classlist-polyfill
import 'svg-classlist-polyfill'

That's it, polyfill will only be added if current environment doesn't already support the methods. Here is how regular usage afterwards might look like:

const icon = document.querySelector('svg.icon')

icon.classList.add('icon--blue')
icon.classList.toggle('icon--rotate')
icon.classList.remove('icon--blue')
icon.classList.contains('icon--blue') === false

Avoid setting the class with icon.className = 'icon icon--blue' as this isn't properly supported in IE11 and will not work together with the polyfill.

Tests

There are a few test cases available in test.js. Serve a simple website with npm test opening this in a browser will run a few test cases quickly indicating whether the polyfill is working well.

Source

Sourcecode partially taken from this Gist.

FAQs

Package last updated on 02 Jul 2023

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