Hi I wrote that html codes and I want change selected item by using jQuery
<select id="slc">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
</select>
I tried this but I can't change
$("#slc").val("2");
$("#slc").prop("selectedIndex", 1);
$("#slc option[value=3]").prop('selected', 'selected');//get option with value 3 and set selected
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<select id="slc">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
</select>
Do like this
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With