I have to make ul act like a dropdown. I'm trying with the following code. If I select a value from ul, it writes in selected_category
but if I want to change the selected value from ul, I can't. Where I am wrong?
$(function() {
$( document.body ).on( 'click', '.category_dropdown li', function( event ) {
var $target = $( event.currentTarget );
$target.closest( '.btn-group' )
.find( '#selected_category' ).text( $target.text() )
.end()
.children( '.category_dropdown' ).dropdown( 'toggle' );
return false;
});
});
<div class="btn-group">
<a class="dropdown-toggle" data-toggle="dropdown" href="#">
<span id="selected_category"></span>
<span class="caret" id="caret_black"></span>
</a>
<ul class="dropdown-menu category_dropdown">
<li class="category_select" >
<a href="#">
Choose
</a>
</li>
<li>
<a href="#"
Value 1
</a>
</li>
<li>
<a href="#">
Value 2
</a>
</li>
</ul>
</div>