Reputation: 71
I have this select:
<select>
<option class="1">1st</option>
<option class="2">other1</option>
<option class="2">other2</option>
<option class="1">2st</option>
<option class="2">other1</option>
<option class="2">other2</option>
</select>
How can I disable the options with class "1"?
Upvotes: 0
Views: 107
Reputation: 3295
Using jQuery, you can do the following (whereas c1
is a valid replacement for 1
)
jQuery("option.c1").attr("disabled", "disabled");
This fetches all elements of tag option
that have a class of c1
set and, for each matched tag, the attribute disabled
is added with value disabled
(this is common practice, as disabled
does not really need an argument, but XML requires an argument for attributes).
Upvotes: 1
Reputation: 1876
<select>
<option class="1">1st</option>
<option class="2">other1</option>
<option class="2">other2</option>
<option class="1">2st</option>
<option class="2">other1</option>
<option class="2">other2</option>
</select>
<script>
$(function(){
$('select').find('option.1').attr('disabled', 'disabled');
});
</script>
Note: Your class names are not following convention
Naming rules:
Upvotes: 5