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

  • SEARCH
  • Home
  • 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 8063089
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T10:54:17+00:00 2026-06-05T10:54:17+00:00

Problem: To search for tab containing class active and remove it while adding an

  • 0

Problem:

To search for tab containing class “active” and remove it while adding an “active” class to current tab on PHP POST submission.

I have a tab menu that looks like this.

HTML code:

<div class="pull-right special-search" id="navtabs">
    <div class="btn-group">
        <a href="#tab1" class="active btn btn-info" data-toggle="tab"><i class="icon-home icon-white"></i>&nbsp;Start</a>
        <a href="#tab2" class="btn btn-info" data-toggle="tab"><i class="icon-book icon-white"></i>&nbsp;Essay</a>
        <a href="#tab3" class="btn btn-info" data-toggle="tab"><i class="icon-ok-sign icon-white"></i>&nbsp;Criteria</a>
        <a href="#tab4" class="btn btn-info" data-toggle="tab"><i class="icon-time icon-white"></i>&nbsp;Activity</a>
    </div>
</div>

To toggle between these tabs I use the following jQuery code:

$('#navtabs a[data-toggle="tab"]').on('shown', function (e) {
    e.target;
    e.relatedTarget;
    $('#navtabs a[data-toggle="tab"]').attr('class','btn btn-info');
    $(this).attr('class','active btn btn-info');
})

So far, so good. Everything works. Now, when I press a button say “submit-updatetime” I want it to be checked with PHP that correspondent to what tab it was sent from. I do this by using a hidden type field:

<input type="hidden" id="submit_button" name="button_pressed">

And then check it with PHP by using the following code:

<?php
    if ($_SERVER['REQUEST_METHOD'] == 'POST') 
    {
        $button = $_POST['button_pressed'];

        if ($button == 'submit-updategrades')
            $tabname = 'tab2';
        else if ($button == 'submit-updatetime')
            $tabname = 'tab4';
    }
?>

To make sure that the user stays on the tab he/she was on I use the following PHP/jQuery:

<?php           
    if (!empty($tabname))
    {
        echo '$("#navtabs a[href=#tab1]").removeClass(\'active\');';
        echo '$("#tab1").removeClass(\'active\');';
        echo '$("#navtabs a[href=#'.$tabname.']").addClass(\'active\');';
        echo '$("#'.$tabname.'").addClass(\'active\');';
    }
?>

This works just fine except that I feel that my last PHP/jQuery solution is flawed. For instance, the #tab1 is only active when you enter the page, not necessarily all the time.

Question:

How do I in the last PHP/jQuery code search for the tab that has the class “active” and remove it while at the same time add it to the active tab produced with $tabname?

  • 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-05T10:54:19+00:00Added an answer on June 5, 2026 at 10:54 am

    Ho wo to find tab that has an active class:

    $(document).ready(function(){
        var tab = $('#navtabs a.active');
    });
    

    Remove that active class on tab found:

    $(document).ready(function(){
        var tab = $('#navtabs a.active');
        tab.removeClass('active');
    });
    

    Find, remove and add active class to a tab provided from PHP:

    <?php           
    if (!empty($tabname)) { ?>
    $(document).ready(function(){
        var active_tab = '#<?php echo $tabname; ?>';
        var tab = $('#navtabs a.active');
        tab.removeClass('active');
        $('#navtabs a').each(function(){
            if($(this).attr('href') == active_tab) {
                $(this).addClass('active');
                return;
            }
        });
    });
    <?php } ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a problem and search for a solution on Google but can't find
I am trying to implement an efficient algorithm for nearest-neighbour search problem. I have
I have a problem with a search query I am using my data contains
I have a problem with my search query, $s_query. The user can search a
I have a problem with my search on my site I don't understand why
Problem: to have a tab completion which takes two words and calculates the best
I have a Google Instant style jQuery search script that queries a PHP file
I have a problem with integration between CouchRest and Sunspot. When I search the
To solve a tricky wiki search problem we've implemented a Javascript solution in a
I'm having trouble wording my problem to search for it, so if anyone could

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.