-1

HTML structure of Tabs:

<div class="txtabs-content">
<div id="tabs-e-0" class="txtabs-pane active in fade-slide"></div>
<div id="tabs-e-1" class="txtabs-pane fade-slide"></div>
<div id="tabs-e-2" class="txtabs-pane fade-slide"></div>
</div>

On page land, the first tab will open. When i set the URL to http://link#tabs-e-1, then the second tab will open.

Is there any way to achieve this using jQuery, to remove the active class on the first one and add it to the second one?

Arunprasanth K V
  • 20,733
  • 8
  • 41
  • 71
tanya
  • 301
  • 2
  • 14

3 Answers3

1

You can select element id from url with window.location.hash and then add class to that element

$( document ).ready(function() {
      $('.txtabs-pane').removeClass('active in');
      var hash = window.location.hash;
      $(hash).addClass('active in');
    });
Gvidas
  • 1,964
  • 2
  • 14
  • 21
1
$( document ).ready(function() {
  $('.txtabs-pane').removeClass('active in');
  var hash = window.location.hash;
  $(hash).addClass('active in');
});
0

You can try the below code (from this SO Q/A):

$("#tabs").tabs({
     select: function(event, ui) {                   
          window.location.hash = ui.tab.hash;
     }
});
Community
  • 1
  • 1
NightOwlPrgmr
  • 1,322
  • 3
  • 21
  • 31
  • Also, check out this other possible [duplicate](http://stackoverflow.com/questions/17961644/jquery-ui-tabs-change-tab-url-jquery-1-10). – NightOwlPrgmr Jun 23 '15 at 11:28