
Security News
AI Agent Lands PRs in Major OSS Projects, Targets Maintainers via Cold Outreach
An AI agent is merging PRs into major OSS projects and cold-emailing maintainers to drum up more work.
jquery.onoff
Advanced tools
Interactive, accessible toggle switches for the web
Transform checkboxes into toggle switches.
Toggle switches made for the web are often solely constructed to change when clicked or tapped, animating side-to-side as they toggle. That's a good start, but some people like to slide toggle switches. Javascript is used for creation and for adding the sliding functionality, but the toggle is purely CSS.
Customize the look of your toggle switch using proto.io's generator.
Supported browsers are the same as those supported by jQuery 2. IE6-8 are not supported.
However, note that IE9 does not support CSS transitions. The toggle switches, but does not animate.
Pointer, touch, and mouse events are supported.
Download the production version (4kb) or the development version and grab the CSS.
define([ 'jquery', 'plugins/jquery.onoff' ], function( $ ) {
$('input[type="checkbox"]').onoff();
});
<script src="jquery.js"></script>
<script src="plugins/jquery.onoff.min.js"></script>
<script>
jQuery(function($) {
$('input[type="checkbox"]').onoff();
});
</script>
All you need is a checkbox:
<input type="checkbox" />
However, you can also start with the generated HTML to avoid FOUC.
<div class="onoffswitch">
<input type="checkbox" class="onoffswitch-checkbox" id="myonoffswitch" />
<label class="onoffswitch-label" for="myonoffswitch">
<div class="onoffswitch-inner"></div>
<div class="onoffswitch-switch"></div>
</label>
</div>
Then initialize onoff:
$('input[type=checkbox]').onoff();
OnOff.defaults = {
// The event namespace
// Should always be non-empty
// Used to bind jQuery events without collisions
namespace: '.onoff',
// The class added to the checkbox
className: 'onoffswitch-checkbox'
};
All methods can be called widget-style.
option()Returns: If getting, the option value; if setting, the jQuery collection for chaining.
The option() method can be called with no arguments to return all options.
var options = $input.onoff('option');
Pass a key to retrieve a single option.
var eventNamespace = $input.onoff('option', 'namespace');
Pass a key and value or an object of key/value pairs to set options.
$input.onoff('option', 'namespace', 'newspace');
$input.onoff('option', {
namespace: 'newspace',
className: 'newclass'
});
disable()Returns: jQuery for chaining
Disables the OnOff instance and unbinds all events.
$input.onoff('disable');
isDisabled()Returns: Boolean
Returns whether the OnOff instance is currently disabled.
var disabled = $input.onoff('isDisabled');
enable()Returns: jQuery for chaining
Enables the OnOff instance, rebinding events and ensuring the proper HTML.
$input.onoff('enable');
wrap()Returns: jQuery for chaining
Ensures the HTML for the toggle switch is correct. This method only adds any missing HTML.
$input.onoff('wrap');
unwrap()Returns: jQuery for chaining
Removes HTML related to OnOff, leaving only the checkbox.
$input.onoff('unwrap');
destroy()Returns: jQuery for chaining
Disables the OnOff instance and removes data, but does not call unwrap().
$input.onoff('destroy');
instance()Returns: OnOff
Returns the OnOff instance.
var instance = $input.onoff('instance');
0.2.4 3/3/2014 Integrate jquery.event.pointertouch into build. 0.1.0 1/15/2014 First release
Thanks go out to the team at proto.io and their elegant CSS.
Copyright (c) 2014 Timmy Willison. Licensed under the MIT license.
FAQs
Interactive, accessible toggle switches for the web
We found that jquery.onoff demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

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.

Security News
An AI agent is merging PRs into major OSS projects and cold-emailing maintainers to drum up more work.

Research
/Security News
Chrome extension CL Suite by @CLMasters neutralizes 2FA for Facebook and Meta Business accounts while exfiltrating Business Manager contact and analytics data.

Security News
After Matplotlib rejected an AI-written PR, the agent fired back with a blog post, igniting debate over AI contributions and maintainer burden.