Last active
January 2, 2016 21:38
-
-
Save lnickers2004/8364308 to your computer and use it in GitHub Desktop.
Bootstrap3: Drop Down list example with jquery code to change button text
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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