I have tried numerous things and nothing seems to be working.
I am using jQuery and Chosen plugin.
Methods I have tried:
var select = jQuery(
Try this:
$("#autoship_option option[selected]").removeAttr("selected");
I am not sure if this applies to the older version of chosen,but now in the current version(v1.4.1) they have a option $('#autoship_option').chosen({ allow_single_deselect:true });
This will add a 'x' icon next to the name selected.Use the 'x' to clear the 'select' feild.
PS:make sure you have 'chosen-sprite.png' in the right place as per the chosen.css so that the icons are visible.
var config = {
'.chosen-select' : {},
'.chosen-select-deselect' : {allow_single_deselect:true},
'.chosen-select-no-single' : {disable_search_threshold:10},
'.chosen-select-no-results': {no_results_text:'Oops, nothing found!'},
'.chosen-select-width' : {width:"95%"}
}
for (var selector in config) {
$(selector).chosen(config[selector]);
}
Use above config and apply class='chosen-select-deselect'
for manually deselect and set the value empty
or if you want deselect option in all combo then apply config like below
var config = {
'.chosen-select' : {allow_single_deselect:true},//Remove if you do not need X button in combo
'.chosen-select-deselect' : {allow_single_deselect:true},
'.chosen-select-no-single' : {disable_search_threshold:10},
'.chosen-select-no-results': {no_results_text:'Oops, nothing found!'},
'.chosen-select-width' : {width:"95%"}
}
for (var selector in config) {
$(selector).chosen(config[selector]);
}
This is more effective than find.
$('select').children('option').first().prop('selected', true)
$('select').trigger("chosen:updated");
In Chrome version 49
you need always this code
$("select option:first").prop('selected', true)
i think you have to assign a new value to the select, so if you want to clear your selection you probably want to assign it to the one that has value = "". I think that you will be able to get it by assigning the value to empty string so .val('')