I am attempting to update the text of the <span class="hideSelect">
element to match the text of the selected <li>
, so that it functions like a <select>
element.
CSS:
.myDrop {
border: 1px solid #ddd;
border-radius: 3px;
padding: 5px 10px;
max- width: 100%;
min-width: 100%;
vertical-align: middle;
}
.mydrop ul {
display: none;
background: #fff;
border: 1px solid #ddd;
border-radius: 3px;
max-height: 250px;
overflow: auto;
}
.mydrop ul li {
padding: 5px 10px;
}
.mydrop ul li:hover {
background: #ddd;
}
JavaScript:
$(".mydrop").click(function(e) {
e.stopPropagation();
$(".mydrop>ul").stop().slideToggle(500);
$(document).click(function(){
$(".mydrop>ul").hide();
});
});
$(".mydrop>ul li").click(function () {
$(".hideSelect").hide();
});
HTML:
<div class="container">
<div class="row">
<div class="col-md-3">
<div class="mydrop">
<div class="myDrop">
<span class="hideSelect">
<span id="caption">my dropdown</span>
<span class="pull-right"><i class="fa fa-caret-down"></i>
</span>
</span>
</div>
<ul id="options">
<li class="visilkl">Hot Dog, Fries and a Soda</li>
<li>Burger, Shake and a Smile</li>
<li>Sugar, Spice and all things nice</li>
<li>Sugar, Spice and all things nice</li>
<li>Sugar, Spice and all things nice</li>
<li>Sugar, Spice and all things nice</li>
<li>Sugar, Spice and all things nice</li>
<li>Sugar, Spice and all things nice</li>
<li>Sugar, Spice and all things nice</li>
<li>Sugar, Spice and all things nice</li>
<li>Sugar, Spice and all things nice</li>
<li>Sugar, Spice and all things nice</li>
<li>Sugar, Spice and all things nice</li>
</ul>
</div>
</div>
</div>
</div>