0

I am trying to set active tab for bootstrap 3 tabs after fetching the view from an ajax call but Its not working.

The view is something like this:

<div class="portlet light ">
    <div class="portlet-title tabbable-line">
        <div class="caption">
            <i class="icon-globe font-dark hide"></i>
            <span class="caption-subject font-dark bold uppercase">TODAY</span>
        </div>
        <ul id="tab" class="nav nav-tabs">
            <li class="active">
                <a href="#tab_1_1" class="active" data-toggle="tab"> Collections </a>
            </li>
            <li>
                <a href="#tab_1_2" data-toggle="tab"> Activities </a>
            </li>
        </ul>
    </div>
    <div class="portlet-body">
        <!--BEGIN TABS-->
        <div class="tab-content">
            <div class="tab-pane active" id="tab_1_1">

And here is the script:

<script type="text/javascript">
function load_page() 
{


    $.ajax(
        {
        url: 'notification_table/',
        type: 'GET',
        dataType: 'html',
        }).done(
                function(data)
                {
                $('#home_view').html(data);
                }
                );

    $('.nav-tabs a[href="#tab_1_2"]').tab('show');
}

 window.onload = function () 
 {
    load_page();
    setInterval(function () {
    load_page(); }, 5000);
 }
</script>

As you can see that I tried doing $('.nav-tabs a[href="#tab_1_2"]').tab('show'); and I also tried $('#tab a[href="#tab_1_2"]').tab('show'); but both are not working.

What am I doing wrong here?

Aurora0001
  • 13,139
  • 5
  • 50
  • 53
Sapnesh Naik
  • 11,011
  • 7
  • 63
  • 98

2 Answers2

0

I think that you may look for "jQuery doesn't work after the content is loaded via AJAX". jQuery doesn't work after content is loaded via AJAX

I fixed my code before but I forget what I did.

Community
  • 1
  • 1
Võ Minh
  • 155
  • 2
  • 12
0

Try to use class="active" only in li not in anchor tag, almost everything right.

 <li class="active">
     <a href="#tab_1_1" data-toggle="tab"> Collections </a>
 </li>
moje_mast_ram
  • 114
  • 13