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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T11:03:51+00:00 2026-05-12T11:03:51+00:00

I have a number of message elements that come in pairs: If element A1

  • 0

I have a number of message elements that come in pairs: If element A1 is shown, then A2 should be hidden, same for B1/B2, C1/C2, and so on. I have the jQuery code working, but it gets verbose:

if (conditionA) {
    $("#a1").show();
    $("#a2").hide();
else {
    $("#a1").hide();
    $("#a2").show();
}

if (conditionB) {
    $("#b1").show();
    $("#b2").hide();
else {
    $("#b1").hide();
    $("#b2").show();
}

//etc...

This seems cumbersome and mind-numbing. Is there a better way to encapsulate the notion that these elements are paired and should show/hide opposite each other? I’ve looked at toggle, but that isn’t right.

  • 1 1 Answer
  • 3 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-12T11:03:51+00:00Added an answer on May 12, 2026 at 11:03 am

    Here’s what I ended up doing:

    I organized the HTML to have the pair of elements paired under a new parent for naming purposes:

    <p id="first_flap"><span class="flap">MsgA1</span><span class="flap">MsgA2</span></p>
    <p id="second_flap"><span class="flap">MsgB1</span><span class="flap">MsgB2</span></p>
    

    Each of the pair has class “flap” on it. Then I can write a function:

    function flip_flap(sel, cond) {
        /* Find sel, then show flaps within it according to cond. */
        var flaps = jQuery(sel + ">.flap");
        var f0 = jQuery(flaps[0]);
        (cond ? f0.show() : f0.hide());
        var f1 = jQuery(flaps[1]);
        (cond ? f1.hide() : f1.show());
    }
    

    I liked the idea of using toggle(), but unfortunately, it doesn’t work for inline elements, only block level, and I needed to use spans.

    Then I can replace my original Javascript with:

    flip_flap("#first_flap", conditionA);
    flip_flap("#second_flap", conditionB);
    

    Much more concise! Thanks.

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

Sidebar

Related Questions

I have a number input that should trigger jQuery on every change. To do
I am trying to have an error message when the use enters a number
We have a number of data objects that realize INotifyPropertyChanged to allow for WPF
I want to calculate , in two lists (same lenght), the number of elements
I have the following code: Queue<Message> localMsgQueue; //inside the constructor localMsgQueue = new ConcurrentLinkedQueue<Message>();
I have a select field that has certain elements faded and disabled that I
I have an XML file: <SMS> <Number>+447761692278</Number> <DateTime>2009-07-27T15:20:32</DateTime> <Message>Yes</Message> <FollowedUpBy>Unassigned</FollowedUpBy> <Outcome></Outcome> <Quantity>0</Quantity> <Points>0</Points> </SMS>
I'm using the jQuery form wizard plugin. I have 20 questions that each have
We have an issue in ActiveMQ where we have a huge number of messages
I have the following ActiveRecord query. It ran fine when the number of messages

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.