I have BootStrap select box and I am trying to find the optgroup of the selected option.
Here's a representation of a bootstrap select box with these options:
<li rel="1">
<div class="div-contain">
<div class="divider"></div>
</div>
<dt>
<span class="text">Option Set 1</span> <!-- I NEED THIS: Option Set 1 -->
</dt>
<a tabindex="0" class="opt " style="">
<span class="text">Option 1</span>
<i class="fa fa-ok icon-ok check-mark"></i>
</a>
</li>
<li rel="2" class="selected">
<a tabindex="0" class="opt " style="">
<span class="text">Option 2</span>
<i class="fa fa-ok icon-ok check-mark"></i>
</a>
</li>
EDIT: My recent try based on @Soren Beck Jensen answer:
$('i.check-mark').closest('li.selected').find('dt>span').text();
This gives me 'Option Set 1' for all and any options I select in the first dropdown.
From Select2 docs: "Furthermore, <optgroup> elements cannot be made selectable. This is a limitation of the HTML specification and is not a limitation that Select2 can overcome."
The <optgroup> tag is used to group related options in a <select> element (drop-down list). If you have a long list of options, groups of related options are easier to handle for a user.
HTML <optgroup> Tag. This tag is used to create a group of the same category options in a drop-down list. The <optgroup> tag is required when there is a long list of the item exists.
Bootstrap Select is a form control that shows a collapsable list of different values that can be selected. This can be used for displaying forms or menus to the user.
Currently your example is wrong, but try this:
$('li.selected').find('dt').find('span').text();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With