I'm using selectize.js for my search form and want to show select list opened by default.
<select id="select-state" name="state[]" multiple class="demo-default" placeholder="Select Models">
<option value="">Select Models</option>
<option value="Tanzania">Tanzania</option>
<option value="Kenya">Kenya</option>
<option value="Uganda">Uganda</option>
<option value="Asia">Asia</option>
<option value="Malaysia">Malaysia</option>
<option value="Japan">Japan</option>
</select>
<script>
$('#select-state').selectize({
maxItems: 5
});
</script>
I have tried different methods but none of them are working.
By jQuery
$('#select-state').show().focus().click();
By CSS
<style>.selectize-dropdown{ display:block!important; visibility:visible!important;}</style>
My Answer:
You can achieve this by using the `open` method provided by selectize.js. Here's an example code snippet to show the select dropdown opened by default:
javascript
// Initialize selectize
var $select = $('#my-select').selectize({
// options
});
// Get selectize instance
var selectize = $select[0].selectize;
// Open the dropdown
selectize.open();
Make sure to replace `#my-select` with the ID of your select element. This code will open the select dropdown by default when the page loads.
Rate this post
4 of 5 based on 7794 votesComments