Search code examples
jquerytabsjquery-tabs

Jquery tabs Check no tabs are selected


Using the jQuery tabs plugin, how would I write a check to see that no tabs are selected. Currently I know that .ui-state-active gets set when a tab is active.

How would I go about doing check on page load as well as after each tab click? Ideally I would like a div to appear saying to select an option when no tabs are selected

HTML

<div id="comments-tabs">
                <ul>
                    <li><a href="#Europe">Europe</a></li>
                    <li><a href="#NorthAmerica">North America</a></li>
                    <li><a href="#SouthAmerica">South America</a></li>
                    <li><a href="#Africa">Africa</a></li>
                    <li><a href="#Asia">Asia</a></li>
                    <li><a href="#Oceania">Oceania</a></li>
                    <li class="resetcontinent"><a href="#" class="resetcontinent">reset</a></li>
                </ul>
                <div id="Europe" class="country">
                   Europe
                </div>
                <div id="NorthAmerica" class="country" style="margin:0 0 0 122px;">
                   North America
                </div>
                <div id="SouthAmerica" class="country" style="margin:0 0 0 244px;">
                  South America
                </div>
                <div id="Africa" class="country" style="margin:0 0 0 368px;">
                   Africa
                </div>
                <div id="Asia" class="country" style="margin:0 0 0 490px;">
                   Asia
                </div>
                <div id="Oceania" class="country" style="margin:0 0 0 611px;">
                   Oceania
                </div>
            </div><!--comments-tabs-->

jQuery

$("#comments-tabs").tabs({collapsible: true, selected: -1});

Solution

  • You can test the selected option which returns the index or -1 if there is no selected tab;

    var nothingSelected = $("#comments-tabs").tabs("option", "selected") === -1;