<script src="http://select2.github.io/select2/select2-3.5.1/select2.js"></script>
<link rel="stylesheet" href="http://select2.github.io/select2/select2-3.5.1/select2.css">
<body>Single select example
<div style="height:400px"> select demo </div>
<div class="selectRow">
<select id="singleSelectExample">
<option></option><!-- Needed to show X image to clear the select -->
<option value="1">Option 1 is a very long option</option>
<option value="2">Option 2</option>
<option value="3">Option 3 is also a very long option</option>
<option value="4">Option 4</option>
<option value="5">Option 5</option>
</select>
</div>
</body>
// Setting default configuration here or you can set through configuration object as seen below
$.fn.select2.defaults = $.extend($.fn.select2.defaults, {
allowClear: true, // Adds X image to clear select
closeOnSelect: true, // Only applies to multiple selects. Closes the select upon selection.
placeholder: 'Select...',
minimumResultsForSearch: 15 // Removes search when there are 15 or fewer options
});
$(document).ready(
function () {
// Single select example if using params obj or configuration seen above
var configParamsObj = {
placeholder: 'Select an option...', // Place holder text to place in the select
minimumResultsForSearch: 3 // Overrides default of 15 set above
};
$("#singleSelectExample").select2(configParamsObj);
});
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.