Skip to content

Instantly share code, notes, and snippets.

@damianwajer
Last active October 15, 2015 13:25
Show Gist options
  • Select an option

  • Save damianwajer/34fbfe042d1095132731 to your computer and use it in GitHub Desktop.

Select an option

Save damianwajer/34fbfe042d1095132731 to your computer and use it in GitHub Desktop.
[JavaScript][jQuery] Example of how to toggle Bootstrap plugin with <select> <option>
/**
* Add support for <select> <option> to Bootstrap plugins
*
* @link http://getbootstrap.com/javascript/
*/
$(".js-select-toggle").on("change", function () {
var $select = $(this);
$select.find("option").each(function () {
var $option = $(this),
$target = $($option.data("target")),
toggle = $option.data("toggle");
if (!$target.length || typeof toggle === "undefined") {
return;
}
switch (toggle) {
case "collapse":
if ($option.is(":selected")) {
$target.collapse("show");
} else {
$target.collapse("hide");
}
break;
case "modal":
if ($option.is(":selected")) {
$target.modal("show");
}
break;
// TODO - other plugins
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment