Stylish Select attempts to replicate the functionality of the browser default select box as closely as possible with support for keyboard navigation, and intelligent positioning.
Stylish Select aims to have a minimal code footprint and weighs in at just over 3KB when minified.
First, include the stylesheet, jQuery and the stylish select .js file in your html head tag.
The plugin can be used to replace any select with the following:
$(document).ready(function(){ $('#my-dropdown').sSelect(); });
You can use the alphabetical and arrow keys to navigate the list as you would a browser default select.
Stylish Select alters the original select on the page, so you can access it's change event:
//change event $('#my-dropdownChange').sSelect().change(function(){alert('changed')});
Stylish Select supports optgroups and also optgroups and options together.
//set value $('#setVal').click(function(){ $('#my-dropdown5').getSetSSValue(4); }); //get value $('#getVal').click(function(){ alert('The value is: '+$('#my-dropdown5').getSetSSValue()); });
Set value to 4
Get value
//add options to select and update $('#addOptions').click(function(){ $('#my-dropdown6').append('<option value="newOpt">New Option</option>').resetSS(); });
If you add or remove options from the initial select element on the page, be sure to call the .resetSS() method on the select to update the Stylish Select replacement.
Add new options to select and update
$('#my-dropdown').sSelect({ddMaxHeight: '300px'});
Stylish Select will always remain visible on the page.