Reputation: 1101
am trying to get the current clicked option text from a multi select.but on change event is only working. on click event not working please check
$('#myoption').change(function () {
alert($(this).children("option").text());
});
Upvotes: 0
Views: 664
Reputation: 303
you could do this:
$('#myoption').change(function () {
console.log($(this).children("option").filter(":selected").text());
});
Upvotes: 0
Reputation: 42054
You can use:
onChange: A function which is triggered on the change event of the options. Note that the event is not triggered when selecting or deselecting options using the select and deselect methods provided by the plugin.
$('#example-getting-started').multiselect({
onChange: function(option, checked, select) {
console.log('Changed option ' + $(option).val() + '.');
}
});
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://code.jquery.com/jquery-2.1.1.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<link rel="stylesheet" href="https://rawgit.com/davidstutz/bootstrap-multiselect/master/dist/css/bootstrap-multiselect.css">
<script src="https://rawgit.com/davidstutz/bootstrap-multiselect/master/dist/js/bootstrap-multiselect.js"></script>
<div class="container">
<select id="example-getting-started" multiple="multiple">
<option value="cheese">Cheese</option>
<option value="tomatoes">Tomatoes</option>
<option value="mozarella">Mozzarella</option>
<option value="mushrooms">Mushrooms</option>
<option value="pepperoni">Pepperoni</option>
<option value="onions">Onions</option>
</select>
</div>
Upvotes: 1