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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T08:12:13+00:00 2026-06-13T08:12:13+00:00

This is a question for the facts on .hide() and .show(). This is a

  • 0

This is a question for the facts on .hide() and .show(). This is a dumbed down version of my code, but it explains it in generality. Since it is code that has already been built, and I am changing and adding to it, I do not want to go back through and change everything to .toggle().

Imagine that you have button 1 that is ALWAYS a .show() and button 2 is ALWAYS a .hide().

Is there any need for an IF statement? Are there any implications in NOT using the IF statement? Are there any implications if you DO use an IF statement?

$('#button1').click(function() {
if (!$("#widget").is(':visible')) { 
  $('#widget').show('fast');
}
});
$('#button2').click(function() {
if ($("#widget").is(':visible')) {  
  $('#widget').hide('fast');
}
});

OR would a direct change suffice? ::

$('#button1').click(function() {
  $('#widget').show('fast');
});

$('#button2').click(function() {
  $('#widget').hide('fast');
});

I’ve been told that there are potential issues if said IF statement is not used. What are the potential problems involved?

  • 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-13T08:12:14+00:00Added an answer on June 13, 2026 at 8:12 am

    The second way is near fine. However, to deal with “fast clicking” issue you may want to consider jQuery’s .stop() or .clearQueue() functions as they will stop any previous animation and continue with the new one.

    Something like:

    $('#button1').click(function() {
        $('#widget').stop().show('fast');
    });
    
    $('#button2').click(function() {
        $('#widget').stop().hide('fast');
    });
    

    The big dif between the two functions is that clearQueue is meant for stoping more than animations (callback functions, listing methods, etc…). .stop() should be all you need in this case, altho you may want to test it in different browsers enabling the different parameters (.stop(false, true) …) and see how it functions in each browser and adjust it to your needs.

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

Sidebar

Related Questions

I think this question has not to do with programming in general, but nevertheless
Ok, let me preface this question with the fact that I am extremely new
This question may sprout from the fact that I'm still confused about context and
Before I ask this question I would to apologise because of the fact that
Please point me to any dupes or better places to post this question that
I'm hitting a wall here and I know this is a simple question, but
I have searched through google and SO for possible answers to this question, but
I don't know if StackOverflow is the right place for this question, but I
This is partly a jquery question, but most javascript. I just don't know javascript
Here are some facts about my app followed by a question My app has

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.