selectbox의 첫번째 option을 선택하고자 한다. prop 메소드를 사용하고자 할 때. ( option 을 선택하면 chage가 실행된다.)
1번
$('#selectList option:first').prop("selected", true).trigger("change");
2번
$("#selectList").prop("selectedIndex", 0).trigger("change");
2가지 방법이 있을 때, 1번보다 2번이 명확하게 잘 실행이 됐다.
prop에 대한 공식 : https://api.jquery.com/prop/
.prop() | jQuery API Documentation
Description: Get the value of a property for the first element in the set of matched elements. The .prop() method gets the property value for only the first element in the matched set. It returns undefined for the value of a property that has not been set,
api.jquery.com
How to make the first option of <select> selected with jQuery
How do I make the first option of selected with jQuery? <select id="target"> <option value="1">...</option> <option value="2">...</option> </select>
stackoverflow.com