jqueryajaxtwitter-bootstrapbootstrap-modalbootstrap-tabs

Bootstrap tabs are not working via AJAX in a modal


It working fine without modal and ajax. But when I load tabbed panel in modal using ajax it does not select Tab Panes.

<!-- Nav tabs -->
<ul class="nav nav-tabs tabs-left">
    <li class="active tab-selection"><a data-toggle="tab" href="#financial">Financial</a></li>
    <li class="tab-selection"><a data-toggle="tab" href="#marketing">Marketing</a></li>
</ul>

<!-- Tab panes -->
<div class="tab-content">
  <div class="tab-pane active" id="financial">Financial Tab</div>
  <div class="tab-pane" id="marketing">Marketing Tab</div>      
</div>

AJAX

$.ajax({
        url : url,
        type : "POST", 
        success:function(data){
            $(".modal-body").html(data);
        }
  });

My Modal

<div aria-hidden="true" aria-labelledby="myModalLabel" role="dialog" tabindex="-1" id="previewForm" class="modal fade">
  <div class="modal-dialog" style="width: 675px">
    <div class="modal-content">
    <div class="modal-header">
        <button data-dismiss="modal" class="close" type="button"><span aria-hidden="true">×</span><span class="sr-only">Close</span></button>
        <h3 id="myModalLabel" class="modal-title">Preview</h3>
    </div>
        <div class="modal-body">
        </div>  
    </div>
 </div>
</div>

Solution

  • I found alternative solution to show tabbed-panel of associated nav-tab like following.

    $(document).ready(function(){
        $(document).on("click",".modal-body li a",function()
        {
            tab = $(this).attr("href");
            $(".modal-body .tab-content div").each(function(){
                $(this).removeClass("active");
            });
            $(".modal-body .tab-content "+tab).addClass("active");
        });
    });