Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/toddmotto/apollo
Standalone cross-browser DOM class manipulation module
https://github.com/toddmotto/apollo
Last synced: 13 days ago
JSON representation
Standalone cross-browser DOM class manipulation module
- Host: GitHub
- URL: https://github.com/toddmotto/apollo
- Owner: toddmotto
- License: other
- Created: 2013-11-09T20:49:02.000Z (almost 11 years ago)
- Default Branch: master
- Last Pushed: 2014-08-19T19:02:16.000Z (about 10 years ago)
- Last Synced: 2024-10-12T08:10:10.359Z (28 days ago)
- Language: JavaScript
- Homepage:
- Size: 404 KB
- Stars: 251
- Watchers: 24
- Forks: 21
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Apollo.js [![Build Status](https://travis-ci.org/toddmotto/apollo.svg)](https://travis-ci.org/toddmotto/apollo)
Apollo is a 1KB standalone DOM class manipulation module that provides a cross-browser wrapper for `addClass`, `hasClass`, `removeClass` and `toggleClass` methods. Apollo uses the modern and blazing fast `classList` methods when available, and falls back to manual class manipulation for legacy support, meaning IE6+ support through to Chrome.
```javascript
// hasClass() returns boolean on single class
apollo.hasClass(element, 'className1'); single as string
apollo.hasClass(element, ['className1']); single as array// addClass() adds single or multiple classes
apollo.addClass(element, 'className1'); // single as string
apollo.addClass(element, ['className1']); // single as array
apollo.addClass(element, 'className1 className2'); // multiple in string
apollo.addClass(element, ['className1', 'className2']); // multiple as array// removeClass() removes single or multiple classes
apollo.removeClass(element, 'className1'); // single as string
apollo.removeClass(element, ['className1']); // single as array
apollo.removeClass(element, 'className1 className2'); // multiple in string
apollo.removeClass(element, ['className1', 'className2']); // multiple as array// toggleClass() toggles single or multiple classes
apollo.toggleClass(element, 'className1'); // single as string
apollo.toggleClass(element, ['className1']); // single as array
apollo.toggleClass(element, 'className1 className2'); // multiple in string
apollo.toggleClass(element, ['className1', 'className2']); // multiple as array
```## Installing with Bower
```
bower install apollo.js
```or use the repository hook:
```
bower install https://github.com/toddmotto/apollo.git
```## Manual installation
Ensure you're using the files from the `dist` directory (contains compiled production-ready code). Ensure you place the script before the closing `
apollo.addClass(document.body, 'js');
apollo.removeClass(document.body, 'no-js');