npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

jquery-classlist

v1.0.3

Published

Re-implementation of jQuery class manipulation methods that utilizes the classList interface

Downloads

21

Readme

jQuery classList plugin

Re-implementation of jQuery class manipulation methods that utilizes the classList interface.

Compatible with jQuery 1.9+.

Rationale

The DOM spec defines the classList interface, allowing for adding/removing/toggling classes or checking if an element contains a specified class using built-in methods as opposed to manually parsing the className field where classes are separated by spaces.

A couple of test suites comparing both implementations:

  1. https://jsperf.com/classlist-v-old-way/18 - small (10) number of classes
  2. https://jsperf.com/classlist-v-old-way/19 - large (100) number of classes

jQuery currently doesn't utilize this interface, one of the reasons being it's not supported by Internet Explorer 9 and it doesn't work on SVGs even in IE 11.

Browser support

Note: in browsers that don't fully support the classList interface (e.g. all IE & Android Browser) the plugin falls back to the built-in jQuery implementation so it doesn't break them.

The following browsers can utilize full functionality of this plugin:

  1. Chrome (for desktop & Android), Edge, Firefox, Opera: Current -1, Current
  2. Safari 7.0+
  3. iOS 7.0+

"Current -1, Current" denotes that the current stable version of the browser and the version that preceded it are supported. For example, if the current version of a browser is 24.x, we support the 24.x and 23.x versions.

In fact the code will work in many older versions, too, but they are not actively tested.

Caveats

Supported browsers with the jQuery classList plugin pass the whole jQuery test suite with a few minor exceptions:

  1. A few tests that check for extra whitespaces in the class attribute or the presence of the class attribute are failing. This is mostly because in Safari up to version 9.x and in current Firefox & Chrome (at the time of writing this section) classList update steps are not performed correctly and there is no way to control that behavior via the classList interface. Relevant bug reports:
    1. Chrome: https://crbug.com/600964
    2. Firefox: https://bugzilla.mozilla.org/show_bug.cgi?id=869788
  2. In Safari 7 passing the same class to classList.add in multiple parameters results in duplicated class names in the class attribute which makes another few tests fail. However, classList.remove removes all duplicated classes so this shouldn't be a problem unless you're parsing the className attribute directly by yourself. This has been fixed in Safari 8.