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

user5005768Himadree picture user5005768Himadree · Sep 5, 2016 · Viewed 13.1k times · Source

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:

Please help.thanks

Answer

James picture James · Sep 5, 2016

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