You can use my functions :
first change your code
<option value="All" selected="selected">All Ratings</option>
to
<option value="All" id="target" selected="selected">All Ratings</option>
and second add between your <script>
tags
$( "#target" ).toggle(function() {
selectAll($( "#divRatings" ))
}, function() {
selectClear($( "#divRatings" ))
});
function selectAll(element){//Select All Function
element.prop('selected', true);
element.selectpicker('refresh');
}
function selectClear(element){//Clear All Function
element.prop('selected', false);
element.selectpicker('refresh');
}
It has been answered but i found a better way of doing.
Just add data-actions-box="true" as attributes of the select tag.
Eg.
<label>Select/deselect all</label>
<select class="selectpicker form-control" data-style="btn-outline-warning" multiple data-actions-box="true">
<optgroup label="Condiments">
<option>Mustard</option>
<option>Ketchup</option>
<option>Relish</option>
</optgroup>
<optgroup label="Breads">
<option>Plain</option>
<option>Steamed</option>
<option>Toasted</option>
</optgroup>
</select>