본문 바로가기
JavaScript

select option에 attribute 추가하기

by ma_ro 2020. 2. 1.

JQUERY 사용할 때

 

$("#countryselect").val('4')
    //OR
$("#countryselect option").val('4').attr("selected", true)

 

바닐라 JavaScript의 경우

 

selectOption.setAttribute('selected', true);
	//or
selectOption.selected = true;

 

참고
 

How to add "selected" in option attribute using Javascript or jQuery?

Below is code for select option and generate using php from database and i try to add selected="selected" to value="4" using jQuery or any javascript:

 

'JavaScript' 카테고리의 다른 글

Node.js 개요  (0) 2020.02.18
change event  (0) 2020.02.01
Storage  (0) 2020.02.01
Date()  (0) 2020.02.01
setInterval()  (0) 2020.02.01

댓글