Trigger change event <select> using jquery

前端 未结 8 1143
别那么骄傲
别那么骄傲 2020-11-28 04:27

is there anyway i could trigger a change event on select box on page load and select a particular option.

Also the function executed by adding the trigger after bin

8条回答
  •  攒了一身酷
    2020-11-28 04:48

    Another working solution for those who were blocked with jQuery trigger handler, that dosent fire on native events will be like below (100% working) :

    var sortBySelect = document.querySelector("select.your-class"); 
    sortBySelect.value = "new value"; 
    sortBySelect.dispatchEvent(new Event("change"));
    

提交回复
热议问题