JSFiddle - React, Tailwind, and code Playground
HTML
<link rel="stylesheet" href="https://raw.github.com/harvesthq/chosen/master/chosen/chosen.css">
<script src="https://raw.github.com/harvesthq/chosen/master/chosen/chosen.proto.js"></script>
<link rel="stylesheet" type="text/css" href="http://harvesthq.github.com/chosen/chosen/chosen.css" />
<div class="cont">
<select id="sl-color" data-placeholder="Choose a Color" class="chzn-select">
<option value=""></option>
<option value="1">Blue</option>
<option value="2">Red</option>
<option value="3">Black</option>
</select>
</div>
<div class="cont">
<select id="sl-size" data-placeholder="Choose a Size" class="chzn-select" disabled="disabled">
<option value=""></option>
<option value="1">10</option>
<option value="2">20</option>
<option value="3">30</option>
</select>
</div>
CSS
select.chzn-select {
width:350px;
}
div.cont {
margin: 10px;
}
JavaScript
// include event.simulate source
/**
* Event.simulate(@element, eventName[, options]) -> Element
*
* - @element: element to fire event on
* - eventName: name of event to fire (only MouseEvents and HTMLEvents interfaces are supported)
* - options: optional object to fine-tune event properties - pointerX, pointerY, ctrlKey, etc.
*
* $('foo').simulate('click'); // => fires "click" event on an element with id=foo
*
**/
(function() {
var eventMatchers = {
'HTMLEvents': /^(?:load|unload|abort|error|select|change|submit|reset|focus|blur|resize|scroll)$/,
'MouseEvents': /^(?:click|mouse(?:down|up|over|move|out))$/
}
var defaultOptions = {
pointerX: 0,
pointerY: 0,
button: 0,
ctrlKey: false,
altKey: false,
shiftKey: false,
metaKey: false,
bubbles: true,
cancelable: true
}
Event.simulate = function(element, eventName) {
var options = Object.extend(Object.clone(defaultOptions), arguments[2] || { });
var oEvent, eventType = null;
element = $(element);
for (var name in eventMatchers) {
if (eventMatchers[name].test(eventName)) {
eventType = name; break;
}
}
if (!eventType)
throw new SyntaxError('Only HTMLEvents and MouseEvents interfaces are supported');
if (document.createEvent) {
oEvent = document.createEvent(eventType);
if (eventType == 'HTMLEvents') {
oEvent.initEvent(eventName, options.bubbles, options.cancelable);
} else {
oEvent.initMouseEvent(eventName, options.bubbles, options.cancelable, document.defaultView,
options.button, options.pointerX, options.pointerY, options.pointerX, options.pointerY,
options.ctrlKey, options.altKey, options.shiftKey, options.metaKey, options.button, element);
}
element.dispatchEvent(oEvent);
} else {
options.clientX = options.pointerX;
options.clientY = options.pointerY;
oEvent = Object.extend(document.createEventObject(),...