Click here to Skip to main content
15,885,953 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to create a page w/ multiple-tabs. I got the source code that using the bootstrap.css and bootstrap.js. Now, I added a button. What I want to do is when I click the button, the current 'red' div becomes a non-active tab-pane, while the 'orange' one becomes the active tab-pane. However, the code I created below does not work. Can you help figure out how to do it? Thanks.



HTML
<html lang="en">
<head>
  <link href="bootstrap/css/bootstrap.css" rel="stylesheet" type="text/css" />
  <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.10.2/jquery.min.js" type="text/javascript"></script>
  <script src="bootstrap/js/bootstrap.js" type="text/javascript"></script>>
</head>

<body>

<div class="container">

<!-------->
<div id="content">
    <ul id="tabs" class="nav nav-tabs" data-tabs="tabs">
        <li class="active"><a href="#red" data-toggle="tab">Red</a></li>
        <li><a href="#orange" data-toggle="tab">Orange</a></li>
        <li><a href="#yellow" data-toggle="tab">Yellow</a></li>
        <li><a href="#green" data-toggle="tab">Green</a></li>
        <li><a href="#blue" data-toggle="tab">Blue</a></li>
    </ul>
    <div id="my-tab-content" class="tab-content">
        <div class="tab-pane active" id="red">
            <h1>Red</h1>
            <p>red red red red red red</p>
            <input id="Button1" type="button" value="button" onclick="btn1_Click();"/>
        </div>
        <div class="tab-pane" id="orange">
            <h1>Orange</h1>
            <p>orange orange orange orange orange</p>
        </div>
        <div class="tab-pane" id="yellow">
            <h1>Yellow</h1>
            <p>yellow yellow yellow yellow yellow</p>
        </div>
        <div class="tab-pane" id="green">
            <h1>Green</h1>
            <p>green green green green green</p>
        </div>
        <div class="tab-pane" id="blue">
            <h1>Blue</h1>
            <p>blue blue blue blue blue</p>
        </div>
    </div>
</div>


<script type="text/javascript">
    jQuery(document).ready(function ($) {
        $('#tabs').tab();
    });

    function btn1_Click() {
        debugger;
        var v = document.getElementById('orange');
        v.className = 'tab-pane active';
        v = document.getElementById('red');
    }
</script>    
</div> <!-- container -->

</body>
</html>
Posted
Comments
s yu 20-Nov-15 13:50pm    
Got answeer from http://stackoverflow.com/questions/19589053/how-to-open-specific-tab-of-bootstrap-nav-tabs-on-click-of-a-particuler-link-usi. Thanks for your review. The related code is shown below:
function btn1_Click() {
debugger;
$(document).ready(function () {
activaTab('orange');
});
function activaTab(tab) {
$('.nav-tabs a[href="#' + tab + '"]').tab('show');
};
Patrice T 20-Nov-15 16:49pm    
If you got the answer, then mark this question as answered or delete it.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900