Giter VIP home page Giter VIP logo

class-manipulator's Introduction

class-manipulator

Chainable class list API for manipulating a DOM Element's classes or a class string.

Installation

npm install class-manipulator

Usage

Add class "foo", remove "bar", add or remove "baz", then apply the changes to the element:

list(document.querySelector(".myDiv")).add("foo").remove("bar").toggle("baz").apply();

Note how the DOM isn't changed until you call .apply(). The class attribute is only ever read once no matter how many changes you make to the list.

You can also create a class list wrapper not associated with any element:

list("foo bar baz").add("nub").remove("bar").toString(); // "foo baz nub"

You can copy a class list to another element like this:

list("foo bar baz").copyTo(someElement).apply();

You can also sort and filter a class list:

function threeCharsLong (str) {
    return str.length === 3;
}

list("foo apple bar baz").filter(threeCharsLong).sort().toString(); // "bar baz foo"

For a full reference of the API, see docs/index.html. You can also take a look at the tests at tests.js to find out what else you can do with the API.

Development

If you want to contribute, do so by making a pull request on GitHub. Make sure you do the following:

  • Update the source code docs if you make changes to the API.
  • Run the test to make sure you didn't break anything.
  • Add new tests if you add new things to the API.
  • Use ESLint on the code and correct any errors reported.

Running tests

If you don't have it yet, install Mocha:

npm install -g Mocha

Run the tests:

mocha tests.js

Updating the docs

You need to have docco installed to update the documentation:

npm install -g docco

To update the docs, run:

docco index.js

class-manipulator's People

Contributors

jsteinbeck avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Forkers

jsteinbeck

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.