javascript - Show HTML class on first tab when you do not know which tab will display first as it is dependent on whether data exists in that field -


i have web page tabbed content. information each tab pulled database. tab displays if content exists. js requires class="active" set on first tab allow load , change colour of tab show active tab.

the problem have don't know tab first, there may not information first tab, not display , tab 2 or 3 show first.

how can 'make tab have class="active" if first'?

html:

<nav class="filters">     <ul class="tabs">         <li class="active"><a href="#" data-tab="uniquename-tab-1">content 1</a></li>         <li><a href="#" data-tab="uniquename-tab-2">content 2</a></li>         <li><a href="#" data-tab="uniquename-tab-3">content 3</a></li>     </ul> </nav> <article class="tab-content has-aside wysiwyg active" id="uniquename-tab-1">     <h1>content 1</h1> </article> <article class="tab-content has-aside wysiwyg" id="uniquename-tab-2">     <h1>content 2</h1> </article> <article class="tab-content has-aside wysiwyg" id="uniquename-tab-3">     <h1>content 3</h1> </article> 

javascript:

function tabs($container) {     $container.each(function() {         $('.tabs > li > a', $container).on('click', function(e) {             e.preventdefault();             var tab_id = $(this).attr('data-tab');             $('.tabs > li', $container).removeclass('active');             $('.tab-content', $container).removeclass('active');             $(this).parent().addclass('active');             $("#"+tab_id, $container).addclass('active');         });     }); } 

$("ul.tabs li:eq(0)").addclass('active'); 

Comments

Popular posts from this blog

c# - How to get the current UAC mode -

postgresql - Lazarus + Postgres: incomplete startup packet -

angularjs - ng-repeat duplicating items after page reload -