Clear dropdown using jQuery Select2

前端 未结 15 2097
情深已故
情深已故 2020-11-28 11:35

I\'m trying to programmatically clear a drop down using the fantastic Select2 library. The drop down is dynamically filled with a remote ajax call using the Select2 qu

15条回答
  •  自闭症患者
    2020-11-28 12:07

    These both work for me to clear the dropdown:

    .select2('data', null)
    .select2('val', null)
    

    But important note: value doesn't get reset, .val() will return the first option even if it's not selected. I'm using Select2 3.5.3

提交回复
热议问题