I have a list of options. When selectting an option in the list I create new elemets and append them to another div.
HTML:
<select multiple="multiple">
<option value="1">One</option>
<option value="2">Two</option>
<option value="3">Three</option>
</select>
<div class="tankListProduct">
// things get appended here
</div>
Script
$(function(){
$("#SelectedProduktValues")
.on("change", function(e) {
var optionValueArray = $(this).val();
var optionValue = optionValueArray[optionValueArray.length-1];
var optionText = $("#SelectedProduktValues option[value='" + optionValue + "']").text();
var $options = $("#SelectedTanksValues > option").clone();
var div = "<div class='col-xs-20 adminRow'>";
div += "<p class='col-xs-20 text-center'>" + optionText + "</p>";
div += "<select class='form-control tankList'</select>";
div += "</div>";
$(".tankListProduct").append(div);
$('.tankList').last().selectpicker();
});
})
This works perfectly and is shown in the fiddle below but I can't figre out how I can detect if an option in the list has been deselected so that I can remove the inserted element that corresponds to that option?
EDIT:
If it was uncelar, this is a multiSelect list