Get optgroup label in Bootstrap Select

I have a BootStrap selection window, and I'm trying to find the optgroup of the selected option.

Here is a bootstrap selection window with these parameters:

<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 attempt, based on @Soren Beck Jensen, replies:

 $('i.check-mark').closest('li.selected').find('dt>span').text(); 

This gives me “Option Set 1” for everyone and any options that I select in the first drop down menu.

+8
jquery html
source share
1 answer

Your example is currently incorrect, but try the following:

 $('li.selected').find('dt').find('span').text(); 
+1
source share

All Articles