1

I have to use jQuery for a project and I am trying to get the value of a selected tab. This is the HTML:

<ul class="nav nav-tabs umb-nav-tabs" ng-if="tabs" model="tabs"><li class="dropdown pull-right tabdrop hide" style="display: list-item;"><a class="dropdown-toggle" data-toggle="dropdown" href="#"><i class="icon-align-justify"></i> <b class="caret"></b></a><ul class="dropdown-menu"></ul></li>
  <!-- ngRepeat: tab in model --><li ng-class="{'tab-error': tabHasError}" ng-repeat="tab in model" val-tab="" class="ng-scope active" style="display: list-item;">
    <a data-toggle="tab" href="#tab1" class="ng-binding">Home</a>
  </li><li ng-class="{'tab-error': tabHasError}" ng-repeat="tab in model" val-tab="" class="ng-scope" style="display: list-item;">
    <a data-toggle="tab" href="#tab2" class="ng-binding">Swiss Home</a>
  </li><li ng-class="{'tab-error': tabHasError}" ng-repeat="tab in model" val-tab="" class="ng-scope" style="display: list-item;">
    <a data-toggle="tab" href="#tab3" class="ng-binding">Brazil Home</a>
  </li><li ng-class="{'tab-error': tabHasError}" ng-repeat="tab in model" val-tab="" class="ng-scope" style="display: list-item;">
    <a data-toggle="tab" href="#tab4" class="ng-binding">Get Started</a>
  </li>
</ul>

I want the HTML of the active tab:

<li ng-class="{'tab-error': tabHasError}" ng-repeat="tab in model" val-tab="" class="ng-scope active" style="display: list-item;">
    <a data-toggle="tab" href="#tab1" class="ng-binding">Home</a>
  </li>

Where it says Home, so I can fire some code based on that. Any help would be appreciated.

0

3 Answers 3

1

You can get that value using the following CSS selector and then calling the HTML-method on it:

var theHtml = $("li.active").html();
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks, this was exactly what I needed.
1

You can try something like this. But I didn't test it. It is just an approach.

Take a look at the each function of JQuery documentation.

$( ".ng-scope" ).each(function() {
  if($(this).hasClass("active")){
    var result = $(this).html();
  }
});

Comments

1

You didn't post any info on what event you wanted to fire that on but if it is an onClick you can do something like:

$(".nav a").click(function() {
    if($(this).hasClass('active')){
        //do what you want with it here
    }
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.