Search code examples
jquerylistjquery-ui-sortableselectedposting

Finding the only visible <div> which contains a dynamic <ul> and returning the <ul> id


I have a bunch of dynamic tabs (div's) such as:

<div id="collection">

  <div id="tab-1">
    <ul id="sortable-tab-1">
      <li>
      </li>
    </ul>
  </div>

  <div id="tab-2" class="hidden">
    <ul id="sortable-tab-2">
      <li>
      </li>
    </ul>
  </div>
  .... etc ...
</div>

I'm looking for the best way to find out which tab (div) is visible using jquery. Since the tabs are dynamic I don't know the id's but I do know which div's are hidden hence leaving me one div that is visible.

I need to somehow find the ul id of the visible div then return the ul id. So that I'm left with 'sortable-tab-1' as my result.

Basically I need to know which tab is selected so I can post the correct sortable list.

JavaScript gives me a head ache!

Can anyone help. Thank you.


Solution

  • $('#collection > div:visible > ul').attr('id')