javascript - How to make option select selected by jquery -
here html.
<select class="height_selected" id="renderheight"> <option>select height</option> <option value="1">123 cm</option> <option value="2">125 cm</option> </select>
i want make option 2 i.e., 125 cm selected.
i tried
$('#1 :selected').text();
but not working.
how can make option 125 selected i.e., value have #1
selected
update have option select
i want make height selected.
<select class="weight_selected" id="renderweight"> <option>select weight</option> <option value="1">100 kg</option> <option value="2">125 kg</option> </select>
use prop
select option
.
$('#renderheight option[value="2"]').prop('selected', true);
code demo
$('option[value="2"]').prop('selected', true);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.0/jquery.min.js"></script> <select class="height_selected" id="renderheight"> <option>select height</option> <option value="1">123 cm</option> <option value="2">125 cm</option> </select>
you can set value using val()
.
$('#renderheight').val(2);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script> <select class="height_selected" id="renderheight"> <option>select height</option> <option value="1">123 cm</option> <option value="2">125 cm</option> </select>
Comments
Post a Comment