I am facing a small issue in my html/jquery code, how would i know, which option group
is selected by me when i select any dropdown list value from code:-
<select id="Category" name="Category"><option value="">Select Category</option>
<optgroup label="Test">
<option value="1">Value 1</option>
</optgroup>
<optgroup label="General">
<option value="2">value 2</option>
<option value="3">value 3</option>
</optgroup>
</select>
I want to select option group value using jquery/javascript.
I have to show a div when the user select an option which is in the General label optgroup
Thanks
You can easily do it, considering your above html code, i am writing jquery code here which work's for me
Jquery code:-
$("#Category").on('change', function () {
var selected = $("option:selected", this);
$(".div_to_show").show();
if (selected.parent()[0].label != "General") {
$(".div_to_show").hide();
}
else {
$(".div_to_show").show();
}
});
Subscribe to our weekly Newsletter & Keep getting latest article/questions in your inbox weekly