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 6826277
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T22:07:41+00:00 2026-05-26T22:07:41+00:00

I am using twitter bootstrap for a project – in particular its tab functions

  • 0

I am using twitter bootstrap for a project – in particular its tab functions (http://twitter.github.com/bootstrap/javascript.html#tabs)

Now I have this tablist and when I press the tab it switches to the content of each individual tab. However, this content is preloaded in the page (the html code for the content of all tabs is already there, you only change the visibility by pressing the tabs).

However I want to only dynamically load content when a certain tab is pressed, so one will get the latest data instead of the data when the whole page was loaded.

I am planning on using jQuery for this. However, how can I make it that when a tab is pressed a certain jquery function is called?

I tried to show an alert when a tab was clicked (if that works, a jQuery function will too), but even that isn’t working:

<script type="text/javascript" src="http://code.jquery.com/jquery.min.js"></script>
<script type="text/javascript" src="http://twitter.github.com/bootstrap/1.4.0/bootstrap-tabs.js"></script>
<script type="text/javascript">
$(function() {
    $('.tabs').bind('click', function (e) {
        e.target(window.alert("hello"))
    });
});
</script>

And my html:

<ul class="tabs" data-tabs="tabs">
  <li class="active"><a href="#tab1">tab 1</a></li>
  <li><a href="#tab2">tab 2</li>
</ul>

<div id="my-tab-content" class="tab-content">
  <div class="tab-pane" id="tab1">
      <h1>Tab1</h1>
      <p>orange orange orange orange orange</p>
  </div>
  <div class="tab-pane" id="tab2">
     <h1>Tab2</h1>
     <p>blue blue blue blue blue</p>
  </div>
</div>

Any idea on how to make this work?

see this for the workings of twitter bootstrap tabs: (http://twitter.github.com/bootstrap/javascript.html#tabs)
and the js file it uses:
http://twitter.github.com/bootstrap/1.4.0/bootstrap-tabs.js

  • 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-05-26T22:07:41+00:00Added an answer on May 26, 2026 at 10:07 pm

    The bind seems to run before the DOM is ready. In addition, your selector seems to be broken and you can bind change only on select elements. You have to work around by clicking and implementing some logic. Try

    $(function() {
        $('.tabs').bind('click', function (e) {
            e.target(window.alert("hello"))
        });
    });
    

    UPDATE

    After consulting with the documentation, it seems that your code was only missing the DOM ready part, the rest wasn’t actually a bug, which means that according to the docs the following should work:

    $(function() {
        $('.tabs').bind('change', function (e) {
            // e.target is the new active tab according to docs
            // so save the reference in case it's needed later on
            window.activeTab = e.target;
            // display the alert
            alert("hello");
            // Load data etc
        });
    });
    

    What caused confusion is that the plugin overrides default selector, making #.tabs valid and also adding a change event to the tab element. Go figure why they decided this syntax was a great idea.

    Anyways you can try the second sample and comment wether the alert is fired before or after the tab change.

    EDIT: fixed jquery exception caused by #.tabs selector

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

Sidebar

Related Questions

Using a modern browser, go to a project in GitHub (e.g., https://github.com/twitter/bootstrap ) Click
Firstly I design the site & convert it into HTML using Twitter bootstrap. The
I have a modal created using Twitter Bootstrap. I want to open using javascript.
I got the following code and im using twitter bootstrap. <div class=span10> <div class=span2>@Html.Label(lblUsername,
I am trying to find only new tweets using Twitter Search. For example: http://search.twitter.com/search?tag=bruins&lang=en&rpp=100&result_type=recent&since=22451745267388417
I am using Twitter Bootstrap in a project, and would like to contrain the
I'm using Twitter Bootstrap 2.0.1 in a Rails 3.1.2 project, implemented with bootstrap-sass. I'm
I am using the latest version of Twitter Bootstrap on a project. I have
I'm using twitter bootstrap to create togglable tabs. Here is the css I'm using:
I am trying to work on a new project using Twitter's Bootstrap framework, but

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.