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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T04:13:58+00:00 2026-06-13T04:13:58+00:00

In an app i’m working on it uses jQuery toggle mostly to open and

  • 0

In an app i’m working on it uses jQuery toggle mostly to open and close divs. I know the same effect can be done using show and hide. I have an example in this jsfiddle. Is either method better than the other? Or is there another method more efficient and compliant to open and close divs only allowing one to be open at a time? Thanks

Also i’m moving my app over to use Twitter Bootstrap if it matters

<div id="wrapper"> Toggle Method
<div id="action-buttons">
    <a class="button" onclick="$('#boxone').toggle();$('#boxtwo').hide();return false;"><span>One</span></a>
    <a class="button" onclick="$('#boxtwo').toggle();$('#boxone').hide();return false;"><span>Two</span></a>
</div>
<div id="boxone" style="display:none;">Box One</div>
<div id="boxtwo" style="display:none;">Box Two</div>
</div>
<div id="wrapper"> Show Hide Method
<div id="action-buttons">
    <a class="button" onclick="$('#showboxone').show();$('#showboxtwo').hide();return false;"><span>One</span></a>
    <a class="button" onclick="$('#showboxtwo').show();$('#showboxone').hide();return false;"><span>Two</span></a>
</div>
<div id="showboxone" style="display:none;">Box One</div>
<div id="showboxtwo" style="display:none;">Box Two</div>
</div>

​

  • 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-13T04:13:59+00:00Added an answer on June 13, 2026 at 4:13 am

    I would suggest removing the style and actions from the HTML part.

    And don’t try to optimize it : there is no performance problems on such basic jQuery actions and the only thing that matter is the readability of the code : be sure your HTML, CSS and Javascript are obvious. Don’t try to make too smart javascript : if you can’t instantly see what it does, there are risks of maintainability problems. And rely on id, classes and specific attributes instead of order properties that won’t keep up when you change your page.

    Here’s how I changed your fiddle : http://jsfiddle.net/PRVm8/

    HTML :

    <div id="wrapper"> Toggle Method
    <div id="action-buttons">
        <span class="button1"  target=boxone>One</span>
        <span class="button1"  target=boxtwo>Two</span>
    </div>
    <div id="boxone" class=box1>Box One</div>
    <div id="boxtwo" class=box1>Box Two</div>
    </div>
    
    <div id="wrapper"> Show Hide Method
    <div id="action-buttons">
        <a class="button2"  target=boxone><span>One</span></a>
        <a class="button2" target=boxtwo><span>Two</span></a>
    </div>
    <div id="showboxone" class=box2>Box One</div>
    <div id="showboxtwo" class=box2>Box Two</div>
    </div>
    ​
    

    Javascript :

    $('.button1[target="boxone"]').click(function(){
        $('#boxtwo').hide();
        $('#boxone').toggle();
    });
    $('.button1[target="boxtwo"]').click(function(){
        $('#boxone').hide();
        $('#boxtwo').toggle();
    });
    $('.button2').click(function(){
        $('.box2').hide();
        $('#show'+$(this).attr('target')).show();
    });
    

    ​

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

Sidebar

Related Questions

App I'm working on uses ARC. I wanted it to process large files, so
My app uses LoadLibrary to load plugins at run-time and users can accidentally try
My app got rejected by Apple three times, all with the same rejection letter,
The app I am working on is supporting android 2.3 upwards. As the download
App is in prism/mvvm/mef and uses loading by attribute like StockTraderRI. My shell window
app.js var win1 = Titanium.UI.createWindow({ title:'Tab 1', backgroundColor: 'black', layout: 'vertical', }); win1.open(); Titanium.App.addEventListener('click',
App with Facebook SDK SSO was working fine in 2.2, now upgraded Samsung Galaxy
My app is crashing with the error code: SIGABRT. Ive done a ton of
The app I'm working on is relatively simple but it is throwing memory warnings.
My app uses the android.support.v4.view.ViewPager class. For each page in the ViewPager, I want

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.