Tiny jQuery Replacement For Select Boxes - Bselect

Tiny jQuery Replacement For Select Boxes - Bselect
File Size: 9.73 KB
Views Total:
Last Update:
Publish Date:
Official Website: Go to website
License: MIT

Bselect is a lightweight yet robust jQuery plugin designed to replace the native HTML select boxes.

The plugin dynamically renders a performant, customizable, searchable, user-friendly dropdown from an object of options. The selected option will be stored in an input field named bselect-input.

Easy to customize and manipulate using the following options, methods and events. Multiple select is supported as well.

A great alternative to the select2 and chosen plugins. 

How to use it:

1. Import the Stylesheet bselect.css and JavaScript bselect.js into the HTML.

<link rel="stylesheet" href="bselect.css" />
<script src="jquery.min.js"></script>
<script src="jquery.bselect.js"></script>

2. Create a container element to hold the dropdown select.

<div id="custom-select"></div>

3. Prepare the data (select options) as follows.

var myData = {
    1 : "Angular", 
    2 : "jQueryScript", 
    3 : "React", 
    4 : "Vue.js"

4. Call the function on the placeholder element and populate the dropdown with options defined in the myData object.

  data : myData

5. Customize the dropdown by overriding the following options.


  // enable/disable live search
  search : true,

  // the width of the dropdown
  width : "200px",

  // custom placeholder text
  defaultText : "Select me",

  // additional CSS classes
  className : "",

  // input name
  inputName : "bselect-input",

  // selected index on init
  selected : 0,

  // open the dropdown on init
  opened : false,

  // close the dropdown after an options is selected
  closeOnSelect : true,

  // render dropdown list above the select element if dropdown will not be in view
  checkInView : true,

  // enable multiple select
  multiple : false,

  // close on select
  closeOnSelect : true,

  // enable/disable ellipsis
  elipsis : true,

  // in ms
  focusDelay : 100,

  // in ms
  doneTypingInterval : 180


6. API methods.

// open the dropdown

// close the dropdown

// toggle the dropdown

// select an option by ID
$('#custom-select').bselect("selectById", 2);

// get the selected option

// append a new option
$('#custom-select').bselect("append", 4, "HTML5")

// prepend an option
$('#custom-select').bselect("prepend", 5, "CSS3")

7. Event handlers.

$('#custom-select').on('open.bselect', function(e,params){
  // on open

$('#custom-select').on('opened.bselect', function(e,params){
  // after open

$('#custom-select').on('close.bselect', function(e,params){
  // on close

$('#custom-select').on('closed.bselect', function(e,params){
  // after close

$('#custom-select').on('toggle.bselect', function(e,params){
  // on toggle

$('#custom-select').on('toggled.bselect', function(e,params){
  // after toggle

$('#custom-select').on('select.bselect', function(e,params){
  // after an item selected

$('#custom-select').on('updated.bselect', function(e,params){
  // after the dropdown is updated



  • Code optimized, fixed preselect added by VKuraica, minified version updated
  • Added option to render dropdown list above the select element if dropdown will not be in view


  • Add multiple pre selected values


  • Fixed for none selected items


  • Multiple selextbox added, comments, optimized search

This awesome jQuery plugin is developed by losmicar. For more Advanced Usages, please check the demo page or visit the official website.