https://github.com/robloach/jquery-once
:heavy_dollar_sign: Act on jQuery elements only once.
https://github.com/robloach/jquery-once
Last synced: about 1 year ago
JSON representation
:heavy_dollar_sign: Act on jQuery elements only once.
- Host: GitHub
- URL: https://github.com/robloach/jquery-once
- Owner: RobLoach
- License: other
- Created: 2013-03-02T22:41:09.000Z (over 13 years ago)
- Default Branch: master
- Last Pushed: 2024-01-04T22:16:13.000Z (over 2 years ago)
- Last Synced: 2025-03-30T18:02:01.661Z (about 1 year ago)
- Language: JavaScript
- Homepage: http://npm.im/jquery-once
- Size: 250 KB
- Stars: 61
- Watchers: 7
- Forks: 20
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE.md
Awesome Lists containing this project
README
# jQuery Once [](https://npmjs.org/package/jquery-once "View this project on NPM")

[](https://npmjs.org/package/jquery-once "View this project on NPM")
> Act on [jQuery](http://jquery.com) elements only once.
Filters out all elements that had the same filter applied on them before. It
can be used to ensure that a function is only applied once to an element.
## Install
Method | Installation
------ | ------------
[npm](http://npmjs.com/package/jquery-once) | `npm install jquery-once --save`
[Composer](https://packagist.org/packages/robloach/jquery-once) | `composer require robloach/jquery-once`
[Bower](http://bower.io/search/?q=jquery-once) | `bower install jquery-once`
[Component](https://github.com/componentjs/component) | `component install RobLoach/jquery-once`
[jsDelivr](http://www.jsdelivr.com/#!jquery.once) | `//cdn.jsdelivr.net/npm/jquery-once@2.3.0/jquery.once.min.js`
[cdnjs](https://cdnjs.com/libraries/jquery-once) | `//cdnjs.cloudflare.com/ajax/libs/jquery-once/2.3.0/jquery.once.js`
## Usage
[See the API documentation for more information on how to use jQuery Once.](https://github.com/RobLoach/jquery-once/blob/master/API.md#readme)
``` javascript
// The following will change the color of each paragraph to red, just once
// for the "changecolor" key.
$('p').once('changecolor').css('color', 'red');
// .once() will return a set of elements that yet to have the once ID
// associated with them. You can return to the original collection set by
// using .end().
$('p')
.once("changecolorblue")
.css("color", "blue")
.end()
.css("color", "red");
// To execute a function on the once set, you can use jQuery's each().
$('div.calendar').once().each(function() {
// Since there is no once ID provided here, the key will be "once".
});
```
## Development
1. Ensure you are using [node](http://nodejs.org) >= 4:
```
node --version
```
2. Install dependencies through [npm](http://npmjs.org):
```
npm install
```
3. Check coding style standard, and automated testing:
```
npm test
```
4. Build `jquery.once.min.js` with:
```
npm run build
```
5. Update API documentation:
```
npm run docs
```
6. Tag and publish the new versions to [npm](http://npmjs.com) with [Semantic
Versioning](http://semver.org/):
```
git add -A
git commit -m "2.3.0"
git tag 2.3.0
git push origin 2.3.0
npm publish
```
## Change Log
[Discover the change history by heading on over to the `CHANGELOG.md` file.](CHANGELOG.md)
## License
Dual licensed under:
- [GPL-2.0](http://opensource.org/licenses/gpl-2.0.php)
- the incredibly [permissive](http://en.wikipedia.org/wiki/Permissive_free_software_licence) [MIT license](http://opensource.org/licenses/MIT)
Copyright © [Rob Loach](http://github.com/RobLoach)