I have some question about jquery selection. In my case, how to match if the option.value
equal something, mark a selected
for it. Online code here
repeat code again. It caused Uncaught TypeError: Object #<HTMLOptionElement> has no method 'val'
, how to work as my hope? Thanks.
<script type="text/javascript">
$(document).ready(function(){
var num = 3;
$("div#selection select.select option").each(function(){
if((this).val()==num){
$(this).attr("selected","selected");
}
});
});
</script>
<div id="selection">
<label>Label1:</label>
<select class="select">
<option value="1">V1</option>
<option value="2">V2</option>
<option value="3">V3</option>
</select>
<label>Label2:</label>
<select class="select">
<option value="4">U1</option>
<option value="5">U2</option>
<option value="6">U3</option>
</select>
</div>