Search code examples
jquerytabsjquery-tabs

enable disable jquery tab


I have a jquery tab container, in which there are two tabs. Now what I want is initially second tab will be disabled. On clicking a button on the first tab second tab will be enabled and open automatically.

<script type="text/javascript">
    $(document).ready(function() {
    //When page loads...
    $(".tab_content").hide(); //Hide all content
    $("ul.tabs li:first").addClass("active").show(); //Activate first tab
    $(".tab_content:first").show(); //Show first tab content
    //On Click Event
    $("ul.tabs li").click(function() {
        $("ul.tabs li").removeClass("active"); //Remove any "active" class
            $(this).addClass("active"); //Add "active" class to selected tab
            $(".tab_content").hide(); //Hide all tab content
            var activeTab = $(this).find("a").attr("href"); //Find the href attribute value to identify the active tab + content
            $(activeTab).fadeIn(); //Fade in the active ID content
            return false;
        });

      });
</script>

<div class="tab-wrapper" id="tab-wrapper">
    <div class="tab-header">
        <ul class="tabs">
                <li><a href="#tab1">overview</a></li>
                <li><a href="#tab2">details</a></li>
            </ul>
    </div>
    <div class="tab_container">
            <div id="tab1" class="tab_content">
                here is the list of the overview
        </div>
            <div id="tab2" class="tab_content">
                Particular Details
            </div>
        </div>
</div>

Solution

  • The way I would tackle this is to use a variable that tracks whether the button has been clicked, setting it to 'false' by default and 'true' when the button has clicked.

    Checking the value of this variable within the click event of the tab links will then allow you to decide whether to show the new tab, do nothing, or perhaps show a message.

    Here's a working example: http://jsbin.com/ijoco5