title: Show Bootstrap tab loaded using Ajax doesn't work the first time it's clicked
body: <p>I'm trying to load the content of a given tab using Ajax.</p>
  
  <p>The first tab I render on the server as being active, and the others I active and load using Ajax.</p>
  
  <p>I've isolated the problem (without Ajax) <a href="http://jsfiddle.net/om3xsesx/" rel="nofollow">here</a>.</p>
  
  <p>HTML:</p>
  
  <pre><code>&lt;h1&gt;Hello, tabs!&lt;/h1&gt;
  
  &lt;div&gt;
      &lt;ul class="nav nav-tabs" role="tablist"&gt;
          &lt;li role="presentation" class="active"&gt;&lt;a href="#home" aria-controls="home" role="tab" data-toggle="tab"&gt;Home&lt;/a&gt;
  
          &lt;/li&gt;
          &lt;li role="presentation"&gt;&lt;a href="#profile" aria-controls="profile" role="tab" data-toggle="tab"&gt;Profile&lt;/a&gt;
  
          &lt;/li&gt;
          &lt;li role="presentation"&gt;&lt;a href="#messages" aria-controls="messages" role="tab" data-toggle="tab"&gt;Messages&lt;/a&gt;
  
          &lt;/li&gt;
          &lt;li role="presentation"&gt;&lt;a href="#settings" aria-controls="settings" role="tab" data-toggle="tab"&gt;Settings&lt;/a&gt;
  
          &lt;/li&gt;
      &lt;/ul&gt;
      &lt;div class="tab-content"&gt;
          &lt;div role="tabpanel" class="tab-pane active" id="home"&gt;...&lt;/div&gt;
      &lt;/div&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>Javascript:</p>
  
  <pre><code>$('a[data-toggle="tab"]').on('shown.bs.tab', function (e) {
      e.preventDefault();
  
      var ref = $(this).attr('href').replace('#', '');
  
      var html = '&lt;div role="tabpanel" class="tab-pane" id="' + ref + '"&gt;Brace yourself SW7 is coming. ' + ref + '&lt;/div&gt;';
  
      var tabContent = $('.tab-content');
  
      if (!tabContent.find('.tab-pane#' + ref).length) {
          tabContent.append(html);
      }
  
      tabContent.find('.tab-pane#' + ref).tab('show');
  });
  </code></pre>
  
  <p>The Home tab is rendered already activated.
  Click in the Profile tab for example, it will append the content but won't activate the tab. Now, if you click in the Home tab and in the Profile tab again, it'll work correctly.</p>
  
  <p>I'm doing something wrong or this is an 'expected' behavior?</p>