I'm trying to trigger a click function on page load with jQuery on chosen's dropdown option so that the follow-up action can take place but haven't been able to get it work.
I've tried:
jQuery("document").ready(function() {
setTimeout(function() {
jQuery("customlist_chzn_o_2").trigger('click');
},10);
or
jQuery("document").ready(function() {
jQuery('#customlist').val(9).trigger("chosen:updated")
});
or
jQuery("document").ready(function() {
jQuery('#customlist_chzn_o_2').trigger("chosen:updated")
});
None of them are working, please note that my select's id is #customlist
the id of dropdown element in chosen which I need to click is #customlist_chzn_o_2
and the value of the select option is 9
Best Answer
If I understand you correctly, you need to trigger the
change
event on the originalselect
, not on the custom or hisoption
s.But when you change the original
select
value, than you should triggerchosen:updated
.https://harvesthq.github.io/chosen/#change-update-events