How to select Option element in Select list by id of an option not value?
I have select html element with 'options' have both 'value' and 'id' values.
What I want is to select the 'option' which has specific 'id' not 'value'. How can I do this using jquery?Update:
Thanx for your answers. Here's my select list:<select style="width:102%" id="appStatusSelect">
<option value="#3366CC" id="0">color1</option>
<option value="orange" id="1">color2</开发者_StackOverflowoption>
</select>
I want to select the option with id=1 for example.
If I've understood you correctly, then all you are looking for is this:
var yourOption = $("#optionId");
$("#<id of your element>")
what's the problem ?
http://api.jquery.com/attribute-equals-selector/
$('option[id="yourid"]');
are you looking for something along this line?
<select id="mySelect" multiple="multiple">
<option value="1">First</option>
<option value="2">Second</option>
<option value="3">Third</option>
<option value="4">Fourth</option>
</select>
<script type="text/javascript">
$(document).ready(function() {
if (!$("#mySelect option:selected").length)
$("#mySelect option[value='3']").attr('selected', 'selected');
});
</script>
精彩评论