jQuery addClass example

Change class name on click in jQuery

by kneidels

HTML

<script src="https://harvesthq.github.io/chosen/chosen.jquery.js"></script>
<link rel="stylesheet" href="https://harvesthq.github.io/chosen/chosen.css">
<select name="myselect" id="myselect" class=" " title=" " disabled="disabled" size="1"><option value="">All</option></select>

<br><br><br><a href="javascript:;" id="trigger">Go</a>&nbsp; &nbsp; <a href="javascript:;" id="trigger2">Reset</a>

CSS

#myselect { width: 150px;}

JavaScript

$("#trigger").click(function(){
	$("#myselect").attr('multiple','multiple').html('<option value="1" selected="selected">1</option><option value="2" selected="selected">2</option><option value="3" selected="selected">3</option><option value="4" selected="selected">4</option>').removeAttr('disabled').attr('size','4');
	$('#myselect').chosen("destroy");
	$("#myselect").chosen({rtl: true, allow_single_deselect: true});	

})

$("#trigger2").click(function(){
	$("#myselect").chosen("destroy");
	$("#myselect").removeAttr('multiple','multiple').attr({'disabled':'disabled','size':'1'}).html('<option value="">All</option>');

})