user5005768 user5005768 - 1 year ago 144
jQuery Question

Bootstrap-Multiselect: How to uncheck and deselect Multiselect options using JQuery

I want to write JQuery code that will uncheck and deselect some options from Bootstrap Multi select.

For example if the multi-select is has following values selected & checked:
enter image description here

I want a JQuery that will output the following

enter image description here

I did the following JQuery which didn't work:

$('#example-optionClass').val('1').prop('checked', flase);
$('#example-optionClass').val('4').prop('checked', flase);
$('#example-optionClass').val('2').prop('checked', true);
$('#example-optionClass').val('6').prop('checked', true);

Here the the Source code:

<!DOCTYPE html>
<html lang="en">
<title>Bootstrap Example</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="">
<script src=""></script>
<script src=""></script>
<!-- Include the plugin's CSS and JS: -->
<script type="text/javascript" src=""></script>
<link rel="stylesheet" href="" type="text/css"/>
<script type="text/javascript">
$(document).ready(function() {
includeSelectAllOption: true, // add select all option as usual
optionClass: function(element) {
var value = $(element).val();

if (value%2 == 0) {
return 'odd'; // reversed
else {
return 'even'; // reversed
<style type="text/css">
#example-optionClass-container .multiselect-container li.odd {
background: #eeeeee;
#example-optionClass-container .multiselect-all {
background: #eeeeee;

<div class="container">
<h2>Bootstrap Multiselect Test</h2>
<div id="example-optionClass-container">
<select id="example-optionClass" multiple="multiple">
<option value="1">Option 1</option>
<option value="2">Option 2</option>
<option value="3">Option 3</option>
<option value="4">Option 4</option>
<option value="5">Option 5</option>
<option value="6">Option 6</option>


Please help.thanks

Answer Source

In MultiSelect to select options you need to use

$('#example-optionClass').multiselect('select', ['2', '6']);

This is saying select the options '2' and '6' from example-optionClass.

And to unselect options you need to use

$('#example-optionClass').multiselect('deselect', ['1', '4']);

This is saying unselect the options '1' and '4' from example-optionClass

If you go to The Methods you will see all the JavaScript methods available to you, it explains how to use the 2 above functions in more detail.

Hope this helps