jquery - How to display selected item in the title of the bootstrap dropdown list ? and how to display selected item on a javascript alert box? -
i have tried lots of examples given in type of questions still can't find how display selected item on title of bootstrap dropdown list , how selected item through javascript. if know code please me links should include in head section. because think may missing in head section. here sample dropdown list.
<div class="btn-group"> <button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown"> option: <span class="selection">option 1</span><span class="caret"></span> </button> <ul class="dropdown-menu" role="menu"> <li><a href="#">option 1</a></li> <li><a href="#">option 2</a></li> <li><a href="#">option 3</a></li> </ul> </div>
i modified html little bit, , added jquery event:
<div class="dropdown"> <button class="btn btn-default dropdown-toggle" type="button" id="dropdownmenu1" data-toggle="dropdown" aria-haspopup="true" aria-expanded="true"> dropdown: <span class="selected"></span> <span class="caret"></span> </button> <ul class="dropdown-menu" aria-labelledby="dropdownmenu1"> <li><a href="#">action</a></li> <li><a href="#">another action</a></li> <li><a href="#">something else here</a></li> <li><a href="#">separated link</a></li> </ul> </div> jquery:
$('div.dropdown ul.dropdown-menu li a').click(function (e) { $('.selected').html($(this).html()); })
Comments
Post a Comment