Bootstrap Multiselect jQuery plugin
Bootstrap Multiselect is a JQuery based plugin to provide an intuitive user interface for using select inputs with the multiple attribute present. Instead of a select a bootstrap button will be shown as dropdown menu containing the single options as checkboxes
Bootstrap Multiselect//
Link the Required Files
First, the jQuery library needs to be included. Then Twitter Bootstrap – both the Javascript library and the CSS stylesheet – needs to be included.
- <!– Include Twitter Bootstrap and jQuery: –>
- <link rel=“stylesheet” href=“css/bootstrap.min.css” type=“text/css”/>
- <script type=“text/javascript” src=“js/jquery.min.js”></script>
- <script type=“text/javascript” src=“js/bootstrap.min.js”></script>
- <!– Include the plugin’s CSS and JS: –>
- <script type=“text/javascript” src=“js/bootstrap-multiselect.js”></script>
- <link rel=“stylesheet” href=“css/bootstrap-multiselect.css” type=“text/css”/>
The jQuery library can also be included using a CDN, for example the Google CDN:
- <script src=“//ajax.googleapis.com/ajax/libs/jquery/2.0.3/jquery.min.js”></script>
Note that the plugin will work both with version 2.x of the jQuery library as well as with version 1.10.x of the jQuery library. So for using the Google CDN you may have to adjust the version.
Create a Select
Now simply use HTML to create your
select
input which you want to turn into a multiselect. Remember to set themultiple
attribute as to get a real multiselect – but do not worry, the plugin can also be used as usual select without themultiple
attribute being present.
- <!– Build your select: –>
- <select id=“example-getting-started” multiple=“multiple”>
- <option value=“cheese”>Cheese</option>
- <option value=“tomatoes”>Tomatoes</option>
- <option value=“mozarella”>Mozzarella</option>
- <option value=“mushrooms”>Mushrooms</option>
- <option value=“pepperoni”>Pepperoni</option>
- <option value=“onions”>Onions</option>
- </select>
Call the Plugin
In the end, simply call the plugin on your
select
. You may also specify further options, see the Options tab for further information.//
- <!– Initialize the plugin: –>
- <script type=“text/javascript”>
- $(document).ready(function() {
- $(‘#example-getting-started’).multiselect();
- });
- </script>
Website: http://davidstutz.github.io/bootstrap-multiselect/
Thanks for reading,
NabeelShahid.com
Recent Comments