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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T16:07:32+00:00 2026-06-12T16:07:32+00:00

Possible Duplicate: Jquery performance: hide() vs is(':visible') – which is faster? Does it make

  • 0

Possible Duplicate:
Jquery performance: hide() vs is(':visible') – which is faster?

Does it make sense to check (by own condition) if element is already hidden before calling jQuery.hide() function? (and analogy with jQuery.show())

Reading function source code, it seems to me, it run over, regardless of element property. Is more time expensive do check or let function set atributes over?

  • 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-12T16:07:33+00:00Added an answer on June 12, 2026 at 4:07 pm

    These kinds of questions are always best answered with an actual performance test and the jsperf system makes it pretty easy to test.

    In a surprise to me, if the desired style is already set, then it does seem to save some performance cycles (in Chrome and Firefox) to check first before setting it.

    You can see a number of different combinations here: http://jsperf.com/hide-vs-check

    As the simplest comparison between these two options:

    elem.style.display = "none";
    elem.style.display = "none";
    

    and

    elem.style.display = "none";
    if (elem.style.display !== "none") {
        elem.style.display = "none";
    }
    

    The second option is a slight bit faster. This suggests that setting the style, even when it’s already set to that value still has a significant cost and it does save time to avoid setting it when it’s not needed.


    Or the jQuery version of the two options:

    elem.style.display = "none";
    elem$.hide()
    

    and

    elem.style.display = "none";
    if (elem$.css("display") !== "none") {
        elem$.hide();
    }
    

    Still shows that the second option is faster when the desired state is already set.


    But, if the state needs to be changed, then the extra test does (obviously) slow you down. The first option here is faster than the second one because the condition just costs extra time if the condition evaluates to true:

    elem.style.display = "block";
    elem$.hide()
    

    and

    elem.style.display = "block";
    if (elem$.css("display") !== "none") {
        elem$.hide();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Performance of jQuery selector with context In the jQuery DOCS it says
Possible Duplicate: jQuery question: what does it really mean? For example, (function (exports, $,
Possible Duplicate: What does jQuery.fn mean? I have some script on a page trying
Possible Duplicate: jQuery event to trigger action when a div is made visible How
Possible Duplicate: jQuery: How to determine which <li> tag was clicked? I have a
Possible Duplicate: JS/jQuery (Hide div, show div on click) I'm new to web development
Possible Duplicate: jQuery get all divs which do not have class attribute I need
Possible Duplicate: Jquery trigger file input I'm working on a form which allows users
Possible Duplicate: jQuery: how do I animate a div rotation? I have a div
Possible Duplicate: jQuery won't parse my JSON from AJAX query So I have parsed

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.