-
Notifications
You must be signed in to change notification settings - Fork 18
Getting Started
npm install chosen-jjjLoad jQuery before Chosen, then load the distributed stylesheet and adapter:
<link rel="stylesheet" href="node_modules/chosen-jjj/dist/css/chosen.css">
<script src="jquery.js"></script>
<script src="node_modules/chosen-jjj/dist/js/chosen.jquery.js"></script>The jQuery adapter also works with AMD and CommonJS loaders. AMD registers a
jquery dependency; CommonJS exports the installed $.fn.chosen function.
For CommonJS, install jQuery alongside Chosen and make a DOM available before
requiring the packages:
const $ = require('jquery');
const chosen = require('chosen-jjj');
$('.chosen-select').chosen();The Prototype adapter remains a browser-global script. See the package boundaries for import paths and integration details.
composer require jjj/chosenThe latest GitHub release includes source and compiled archives. Applications normally need one adapter and the compiled CSS from dist/.
<label for="project-members">Project members</label>
<select id="project-members" class="chosen-select" multiple
data-placeholder="Choose project members">
<option>Ada Lovelace</option>
<option>Grace Hopper</option>
<option>Margaret Hamilton</option>
</select>Initialize it after the element and dependencies are available:
$(".chosen-select").chosen();Chosen keeps the original select in the document. Read and submit its value exactly as you would without Chosen.
Change the native select first, then tell Chosen to rebuild:
$("#project-members")
.append('<option value="new">New teammate</option>')
.trigger("chosen:updated");$("#project-members").chosen("destroy");The maintained npm package is named chosen-jjj; it does not replace the abandoned chosen-js package in place.
- Replace the package dependency.
- Replace old asset paths with
chosen-jjj/dist/...paths. - Rebuild application assets.
- Review the changelog, especially developer notes for markup changes.
- Test application CSS that targets Chosen’s generated structure.
The default initialization and underlying select behavior remain compatible. New behaviors are generally opt-in.
Chosen · jQuery demo · Vanilla demo · React demo · Options · Releases · MIT License