Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8407101
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T23:17:06+00:00 2026-06-09T23:17:06+00:00

so i understand bootstrap doesnt have default support for ajax called content for tabs,

  • 0

so i understand bootstrap doesnt have default support for ajax called content for tabs, as jQuery UI does.

i have managed with the helps of other questions here, to come up with the following solution, that kind of works:

    <div class="tabbable">
      <ul class="nav nav-tabs">
        <li class="active"><a data-toggle="tab" href="#tab1"> tab 1</a></li>
        <li><a data-toggle="tab" href="#tab2">tab 2</a></li>
        <li><a data-toggle="tab" href="#tab3">tab 3</a></li>
        <li><a data-toggle="tab" class="ajax" href="test.html">tab 4 - ajax</a></li>
      </ul>
      <div class="tab-content">
        <div id="tab1" class="tab-pane active"> tab 1 content </div>
        <div id="tab2" class="tab-pane"> tab 2 content </div>
        <div id="tab3" class="tab-pane"> tab 3 content </div>
      </div>
    </div>

JS:

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

            $('.ajax').click(function (e) {
              var thisTab = e.target // activated tab
              var pageTarget = $(thisTab).attr('href');
              //get number of li in list of tabs:
              var itemNumber = $(this).parent().index()+1;
              $("#tab"+itemNumber).load(pageTarget);

            });
        });
    </script>

this seems to work perfectly – it finds the destination href of the anchor, and it works out the order of the

  • .

    i have 2 questions:

    1) i want to work out programatically is tab #tab4 exists, and if so – then insert the content via ajax.
    i am using:
    if ($(“#tab”+itemNumber).length > 0)

    but this seems to give the opposite result – ie, if it is there, it tells me its not.
    whats up with that? – weird!

    and 2) if i have i do have #tab4 (lets say i have put it in statically for now), then the content from test.html is loaded in successfully (yay) – but my issue is that now i cant get the tabs to switch to make #tab4 the active one. I have tried applying the “active” class, and have also tried reapplying the tab() call, but that also doesnt work.

    any ideas?

    thanks in advance!

    EDIT: here is a jsfiddle to play with: http://jsfiddle.net/kneidels/wnHEF/1/

    • 1 1 Answer
    • 0 Views
    • 0 Followers
    • 0
    Share
    • Facebook
    • Report

    Leave an answer
    Cancel reply

    You must login to add an answer.

    Forgot Password?

    Need An Account, Sign Up Here

    1 Answer

    • Voted
    • Oldest
    • Recent
    • Random
    1. Editorial Team
      Editorial Team
      2026-06-09T23:17:07+00:00Added an answer on June 9, 2026 at 11:17 pm

      Removing the ‘active’ class, and then applying it to the specific tab-pane seems to work.

      $('.tab-pane').removeClass('active');
      $('#tab' + itemNumber).addClass('active');
      

      JSFiddle


      Using load() in your JSFiddle example also works as expected in my example.

      JSFiddle

      Regarding dynamically creating the pane, your conditional test works for me, although it could be simplified:

      if (!$('#tab' + itemNumber).length) { /* create new tab */ }
      

      A simple test seemed to work fine:

      for (var i = 0; i < 6; i++) {
        console.log("#tab" + i + " found: " + !!$('#tab' + i).length);
      }
      
      // #tab0 found: false
      // #tab1 found: true
      // #tab2 found: true
      // #tab3 found: true
      // #tab4 found: true
      // #tab5 found: false
      

      JSFiddle

      • 0
      • Reply
      • Share
        Share
        • Share on Facebook
        • Share on Twitter
        • Share on LinkedIn
        • Share on WhatsApp
        • Report

    Sidebar

    Related Questions

    I have recently started to use Twitter Bootstrap and trying to understand how it
    All of the jQuery plugins for Twitter Bootstrap follow the same basic pattern of
    I have very strange error I can't understand. I started a new project throw
    Hi everyone I have a compatibility problem with a simple jquery plugin i've done
    Please feel free to correct me, but from what I understand of the bootstrap
    I have been working for a while now with responsive design, and twitter's bootstrap
    I understand what System.WeakReference does, but what I can't seem to grasp is a
    I understand that some countries have laws regarding website accessibility. In general, what are
    I have a very simple test case I am using to try to understand
    I am using Twitter Bootstrap, but can't understand How to set margin 0 0

    Explore

    • Home
    • Add group
    • Groups page
    • Communities
    • Questions
      • New Questions
      • Trending Questions
      • Must read Questions
      • Hot Questions
    • Polls
    • Tags
    • Badges
    • Users
    • Help
    • SEARCH

    Footer

    © 2021 The Archive Base. All Rights Reserved
    With Love by The Archive Base

    Insert/edit link

    Enter the destination URL

    Or link to existing content

      No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.