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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T07:25:00+00:00 2026-05-29T07:25:00+00:00

I have two links, .sp and .sl when you click they change the visibility

  • 0

I have two links, “.sp” and “.sl” when you click they change the visibility of some content (“#live”) and (“#paid”), a low level type of tab interface i guess. I ad a class of ‘active’ on click and remove the class on the other link if it had it. This seems a bit bloated for such a small function, is there a better way to write this?

$(function() {
    $('#live').hide();
    $('.sp').click(function() {
        $(this).addClass('active');
        $('#paid').show();
        $('#live').hide();
        $('.sl').removeClass('active');
    });
    $('.sl').click(function() {
        $(this).addClass('active')
            $('#live').show();
            $('#paid').hide();
            $('.sp').removeClass('active');
    });
});
  • 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-29T07:25:01+00:00Added an answer on May 29, 2026 at 7:25 am

    I’d suggest a utility function that can do the common work for you and be called both places.

    $(function() {
        function clickCommon(current, newItem, oldItem, deactive) {
            $(current).addClass('active');
            $(newItem).show();
            $(oldItem).hide();
            $(deactive).removeClass('active');    
        }
    
        $('#live').hide();
        $('.sp').click(function() {
            clickCommon(this, "#paid", "#live", ".sl");
        });
        $('.sl').click(function() {
            clickCommon(this, "#live", "#paid", ".sp");
        });
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following two links in my main menu, and I have some
I have two links I use for sorting. One by Make and one by
I have two links, one with id #calendar_arrival_open and another with #calendar_departure_open. Both links
I have two links with classes (login-form and register-form) relevant to their target forms
lets say i have two pages links.html & contents.php ... first page contains only
For technical reasons on a site we may have two or more links that
Let's say I have two tables: Category and Product , and Product links to
I have a database that which contains two tables, links and tour. Tour is
I have two links on a page. When the user clicks on one link,
I use the following code for two links: a.vote-down-0 and a.vote-up-0, they do the

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.