how to check which select option group is selected using jquery

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 label="General">
<option value="2">value 2</option>
<option value="3">value 3</option>

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


Asked by:- manish
: 6021 At:- 5/12/2017 12:35:52 PM
jquery html javascript

1 Answers
profileImage Answered by:- vikas_jk

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);
            if (selected.parent()[0].label != "General") {
            else {

At:- 5/12/2017 12:53:59 PM
thank you , this works perfectly fine for me 0
By : manish - at :- 5/12/2017 1:01:34 PM

Login/Register to answer
Register directly by posting answer/details

Full Name *

Email *

By posting your answer you agree on privacy policy & terms of use