If I hardcode the data for a dropdown then I am able to get the dropdown selection showing using my code below:
HTML
<div class="btn-group" role="group">
<button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
<span id="make-selected">Make</span> <span class="caret"></span>
</button>
<ul class="dropdown-menu" id="make-dropdown">
<li><a href="#">Oldsmobile</a></li>
<li><a href="#">Ford</a></li>
<li><a href="#">Volkswagen</a></li>
<li><a href="#">Chrysler</a></li>
<li><a href="#">Pontiac</a></li>
</ul>
</div>
JS
$('.dropdown-menu a').click(function(){
$('#make-selected').text($(this).text());
});
My issue is if I am loading my data from another source then it no longer shows the selection as shown below.
// the input for this is just a JSON file.
function populateDropdown(jsonData) {
for (var m in jsonData) {
$('#make-dropdown').append('<li><a href="#" data-maker="' + jsonData[m] + '">' + jsonData[m] + '</a></li>')
}
}
$('.dropdown-menu a').click(function(){
$('#make-selected').text($(this).text());
console.log("CLICKED" + this);
});
The dropdown list gets populated but once I click the selection nothing happens.