Skip to content

Instantly share code, notes, and snippets.

@lnickers2004
Last active January 2, 2016 21:38
Show Gist options
  • Save lnickers2004/8364308 to your computer and use it in GitHub Desktop.
Save lnickers2004/8364308 to your computer and use it in GitHub Desktop.
Bootstrap3: Drop Down list example with jquery code to change button text
<div class="dropdown">
<button id="pickButton" class="btn btn-success">Pick One...</button>
<button class="btn btn-success" data-toggle="dropdown"><span class="caret"></span></button>
<ul id="reasonDropdown" class="dropdown-menu">
<li><a href="#" tabindex="-1">Reason</a></li>
<li><a href="#" tabindex="-1">Ordering a White Russian</a></li>
<li><a href="#" tabindex="-1">Complaint</a></li>
<li><a href="#" tabindex="-1">I am lost</a></li>
</ul>
</div>
//add a self executing anonymous function to wrap our code so
//its not in the global scope
(function () {
//self executing anaonymous function
"use strict"
//get a reference to the button
$pickButton = $("#pickButton");
//wireup a callback to handle menu clicks
$("#reasonDropdown li a").on("click", function () {
var reason = $(this).text();// get value of the text in the
//menu it anchor that was clicked
$pickButton.text(reason);//set the text on the pick button!
});
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment