{"id":14972344,"url":"https://github.com/gitbrent/bootstrap4-toggle","last_synced_at":"2025-10-01T20:32:22.939Z","repository":{"id":41125036,"uuid":"153549658","full_name":"gitbrent/bootstrap4-toggle","owner":"gitbrent","description":"Bootstrap 4 Switch Button / Toggle","archived":false,"fork":true,"pushed_at":"2023-03-14T10:09:21.000Z","size":1714,"stargazers_count":212,"open_issues_count":40,"forks_count":67,"subscribers_count":9,"default_branch":"master","last_synced_at":"2025-01-15T22:29:31.452Z","etag":null,"topics":["bootstrap","bootstrap-4","bootstrap-widget","bootstrap4","bootstrap4-checkbox","bootstrap4-switch","bootstrap4-switch-button"],"latest_commit_sha":null,"homepage":"https://gitbrent.github.io/bootstrap4-toggle/","language":"HTML","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":"minhur/bootstrap-toggle","license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/gitbrent.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-10-18T02:08:40.000Z","updated_at":"2024-11-30T09:15:05.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/gitbrent/bootstrap4-toggle","commit_stats":null,"previous_names":[],"tags_count":14,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gitbrent%2Fbootstrap4-toggle","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gitbrent%2Fbootstrap4-toggle/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gitbrent%2Fbootstrap4-toggle/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gitbrent%2Fbootstrap4-toggle/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/gitbrent","download_url":"https://codeload.github.com/gitbrent/bootstrap4-toggle/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":234897368,"owners_count":18903646,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["bootstrap","bootstrap-4","bootstrap-widget","bootstrap4","bootstrap4-checkbox","bootstrap4-switch","bootstrap4-switch-button"],"created_at":"2024-09-24T13:46:46.462Z","updated_at":"2025-10-01T20:32:17.584Z","avatar_url":"https://github.com/gitbrent.png","language":"HTML","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![MIT Licence](https://img.shields.io/github/license/gitbrent/bootstrap4-toggle.svg)](https://opensource.org/licenses/mit-license.php)   [![Bootstrap 4.2.1](https://img.shields.io/badge/bootstrap-4.3.1-green.svg?style=flat-square)](https://getbootstrap.com/docs/4.1)  [![Known Vulnerabilities](https://snyk.io/test/npm/bootstrap4-toggle/badge.svg)](https://snyk.io/test/npm/bootstrap4-toggle)  [![npm downloads](https://img.shields.io/npm/dm/bootstrap4-toggle.svg)](https://www.npmjs.com/package/bootstrap4-toggle)  [![JSDelivr Badge](https://data.jsdelivr.com/v1/package/gh/gitbrent/bootstrap4-toggle/badge)](https://www.jsdelivr.com/package/gh/gitbrent/bootstrap4-toggle)\n\n# Bootstrap 4 Toggle\n\n**Bootstrap 4 Toggle** is a bootstrap plugin/widget that converts checkboxes into toggles.\n\n**************************************************************************************************\n\n#### Library Distributions\nProject                                                                                    |Description\n-------------------------------------------------------------------------------------------|-------------------------------------------------------\n[bootstrap4-toggle](https://github.com/gitbrent/bootstrap4-toggle)                         | Supports bootstrap4 (requires jQuery)\n[bootstrap-switch-button](https://github.com/gitbrent/bootstrap-switch-button)             | Supports bootstrap4+ (ES6 class, no dependencies)\n[bootstrap-switch-button-react](https://github.com/gitbrent/bootstrap-switch-button-react) | Supports bootstrap4+ (React component, no dependencies)\n\n# Demos\n**Demos and API Docs:** https://gitbrent.github.io/bootstrap4-toggle/  \n\n![Demo GIF](https://github.com/gitbrent/bootstrap4-toggle/blob/master/doc/bootstrap4-toggle-demo.gif?raw=true)\n\n\u003c!-- START doctoc generated TOC please keep comment here to allow auto update --\u003e\n\u003c!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE --\u003e\n**Table of Contents**  *generated with [DocToc](https://github.com/thlorenz/doctoc)*\n\n- [Installation](#installation)\n  - [CDN](#cdn)\n  - [Download](#download)\n  - [NPM](#npm)\n  - [Yarn](#yarn)\n- [Usage](#usage)\n  - [Initialize With HTML](#initialize-with-html)\n  - [Initialize With Code](#initialize-with-code)\n- [API](#api)\n  - [Options](#options)\n  - [Methods](#methods)\n- [Events](#events)\n  - [Event Propagation](#event-propagation)\n  - [Stopping Event Propagation](#stopping-event-propagation)\n  - [API vs Input](#api-vs-input)\n\n\u003c!-- END doctoc generated TOC please keep comment here to allow auto update --\u003e\n\n**************************************************************************************************\n\n# Installation\n\n## CDN\n```html\n\u003clink href=\"https://cdn.jsdelivr.net/gh/gitbrent/bootstrap4-toggle@3.6.1/css/bootstrap4-toggle.min.css\" rel=\"stylesheet\"\u003e  \n\u003cscript src=\"https://cdn.jsdelivr.net/gh/gitbrent/bootstrap4-toggle@3.6.1/js/bootstrap4-toggle.min.js\"\u003e\u003c/script\u003e\n```\n\n## Download\n[Latest GitHub Release](https://github.com/gitbrent/bootstrap4-toggle/releases/latest)\n\n## NPM\n```ksh\nnpm install bootstrap4-toggle\n```\n\n## Yarn\n```ksh\nyarn add bootstrap4-toggle\n```\n\n# Usage\n\n## Initialize With HTML\nSimply add `data-toggle=\"toggle\"` to automatically convert a plain checkbox into a bootstrap 4 toggle.\n\n```html\n\u003cinput id=\"chkToggle\" type=\"checkbox\" data-toggle=\"toggle\"\u003e\n```\n\n## Initialize With Code\nToggles can also be initialized via JavaScript code.  \n\nEX: Initialize id `chkToggle` with a single line of JavaScript.\n```html\n\u003cinput id=\"chkToggle\" type=\"checkbox\" checked\u003e\n\u003cscript\u003e\n  $(function(){\n    $('#chkToggle').bootstrapToggle();\n  });\n\u003c/script\u003e\n```\n\n# API\n\n## Options\n* Options can be passed via data attributes or JavaScript\n* For data attributes, append the option name to `data-` (ex: `data-on=\"Enabled\"`)\n\n```html\n\u003cinput type=\"checkbox\" data-toggle=\"toggle\" data-on=\"Enabled\" data-off=\"Disabled\"\u003e\n\u003cinput type=\"checkbox\" id=\"toggle-two\"\u003e\n\u003cscript\u003e\n  $(function() {\n    $('#toggle-two').bootstrapToggle({\n      on: 'Enabled',\n      off: 'Disabled'\n    });\n  })\n\u003c/script\u003e\n```\n\nName      |Type       |Default    |Description                 |\n----------|-----------|----------|----------------------------|\n`on`      |string/html|\"On\"      |Text of the on toggle\n`off`     |string/html|\"Off\"     |Text of the off toggle\n`size`    |string     |\"normal\"  |Size of the toggle. Possible values are: `large`, `normal`, `small`, `mini`.\n`onstyle` |string     |\"primary\" |Style of the on toggle. Possible values are: `primary`,`secondary`,`success`,`danger`,`warning`,`info`,`light`,`dark`\n`offstyle`|string     |\"light\"   |Style of the off toggle. Possible values are: `primary`,`secondary`,`success`,`danger`,`warning`,`info`,`light`,`dark`\n`style`   |string     |           |Appends the value to the class attribute of the toggle. This can be used to apply custom styles. Refer to Custom Styles for reference.\n`width`   |integer    |*null*     |Sets the width of the toggle. if set to *null*, width will be auto-calculated.\n`height`  |integer    |*null*     |Sets the height of the toggle. if set to *null*, height will be auto-calculated.\n\n## Methods\nMethods can be used to control toggles directly.\n\n```html\n\u003cinput id=\"toggle-demo\" type=\"checkbox\" data-toggle=\"toggle\"\u003e\n```\n\nMethod     |Example                                         |Description\n-----------|------------------------------------------------|------------------------------------------\ninitialize | `$('#toggle-demo').bootstrapToggle()`          |Initializes the toggle plugin with options\ndestroy    | `$('#toggle-demo').bootstrapToggle('destroy')` |Destroys the toggle\non         | `$('#toggle-demo').bootstrapToggle('on')`      |Sets the toggle to 'On' state\noff        | `$('#toggle-demo').bootstrapToggle('off')`     |Sets the toggle to 'Off' state\ntoggle     | `$('#toggle-demo').bootstrapToggle('toggle')`  |Toggles the state of the toggle on/off\nenable     | `$('#toggle-demo').bootstrapToggle('enable')`  |Enables the toggle\ndisable    | `$('#toggle-demo').bootstrapToggle('disable')` |Disables the toggle\n\n# Events\n\n## Event Propagation\nNote All events are propagated to and from input element to the toggle.\n\nYou should listen to events from the `\u003cinput type=\"checkbox\"\u003e` directly rather than look for custom events.\n\n```html\n\u003cinput id=\"toggle-event\" type=\"checkbox\" data-toggle=\"toggle\"\u003e\n\u003cdiv id=\"console-event\"\u003e\u003c/div\u003e\n\u003cscript\u003e\n  $(function() {\n    $('#toggle-event').change(function() {\n      $('#console-event').html('Toggle: ' + $(this).prop('checked'))\n    })\n  })\n\u003c/script\u003e\n```\n\n## Stopping Event Propagation\nPassing `true` to the on/off methods will enable the silent option to prevent the control from propagating the change event in\ncases where you want to update the controls on/off state, but do not want to fire the onChange event.\n\n```html\n\u003cinput id=\"toggle-silent\" type=\"checkbox\" data-toggle=\"toggle\"\u003e\n\u003cbutton class=\"btn btn-success\" onclick=\"toggleApiOnSilent()\" \u003eOn by API (silent)\u003c/button\u003e\n\u003cbutton class=\"btn btn-success\" onclick=\"toggleApiOffSilent()\"\u003eOff by API (silent)\u003c/button\u003e\n\u003cbutton class=\"btn btn-warning\" onclick=\"toggleApiOnNotSilent()\"\u003eOn by API (not silent)\u003c/button\u003e\n\u003cbutton class=\"btn btn-warning\" onclick=\"toggleApiOffNotSilent()\"\u003eOn by API (not silent)\u003c/button\u003e\n\u003cscript\u003e\n  function toggleApiOnSilent() {\n    $('#toggle-silent').bootstrapToggle('on', true);\n  }\n  function toggleApiOffSilent() {\n    $('#toggle-silent').bootstrapToggle('off', true);\n  }\n  function toggleApiOnNotSilent() {\n    $('#toggle-silent').bootstrapToggle('on');\n  }\n  function toggleApiOffNotSilent() {\n    $('#toggle-silent').bootstrapToggle('off');\n  }\n\u003c/script\u003e\n```\n\n## API vs Input\nThis also means that using the API or Input to trigger events will work both ways.\n\n```html\n\u003cinput id=\"toggle-trigger\" type=\"checkbox\" data-toggle=\"toggle\"\u003e\n\u003cbutton class=\"btn btn-success\" onclick=\"toggleApiOn()\" \u003eOn by API\u003c/button\u003e\n\u003cbutton class=\"btn btn-danger\"  onclick=\"toggleApiOff()\"\u003eOff by API\u003c/button\u003e\n\u003cbutton class=\"btn btn-success\" onclick=\"toggleInpOn()\" \u003eOn by Input\u003c/button\u003e\n\u003cbutton class=\"btn btn-danger\"  onclick=\"toggleInpOff()\"\u003eOff by Input\u003c/button\u003e\n\u003cscript\u003e\n  function toggleApiOn() {\n    $('#toggle-trigger').bootstrapToggle('on')\n  }\n  function toggleApiOff() {\n    $('#toggle-trigger').bootstrapToggle('off')  \n  }\n  function toggleInpOn() {\n    $('#toggle-trigger').prop('checked', true).change()\n  }\n  function toggleInpOff() {\n    $('#toggle-trigger').prop('checked', false).change()\n  }\n\u003c/script\u003e\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgitbrent%2Fbootstrap4-toggle","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgitbrent%2Fbootstrap4-toggle","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgitbrent%2Fbootstrap4-toggle/lists"}