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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T07:19:51+00:00 2026-06-09T07:19:51+00:00

I have a little web app in which I show and hide DIVs a

  • 0

I have a little web app in which I show and hide DIVs a lot. Sometimes, however, I need to add a CSS class to that div that hides the div (using display:none rather than jQuery’s hide() function) because I still need to know if the given div was initial shown on the screen. I typically use jQuery’s addClass and removeClass accordingly.

However, I am running into a problem when doing this. It seems like if the div has been hidden and shown before, adding a display:none class to the div will not work.

I was wondering if there was any kind of work around that I could use without resorting to using hide().

Here are some JSFiddle examples to show you what I am talking about:

JSFiddle Example 1 – Will properly Hide the DIV using the CSS class.

JSFiddle Example 2 – After using the show() and hide() functions, it will not properly hide the DIV using the CSS class.

  • 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-09T07:19:52+00:00Added an answer on June 9, 2026 at 7:19 am

    The problem you encounter is that jQuery’s hide()-function adds inline CSS to the element:

    <div id="divTest" class="hideDiv" style="display: block;">
    

    Where display is set to block, so your hideDiv class will get overwritten by the inline since it’s considered “stricter” in CSS rules. A somewhat ugly workaround to this is to change your hideDiv CSS rule to this:

    .hideDiv
    {
        display: none !important;
    }
    

    The !important part will make it take precedence over the inline CSS.

    Edit:
    Additionally, I would recommend sticking with one way to show/hide stuff (your own or jQuery). Use jQuery show/hide for all showing/hiding but you can still add a class for tracking, just don’t have that class hide your elements.

    So chance the button JavaScript to something like this:

    $("#btnHideDiv").on("click", function()
    {
        $("#divTest").addClass("hideDiv");
        $("#divTest").hide();
    });
    

    And completely remove the hiding CSS from the hideDiv class. Now you can still use jQuery to find the div(s) hidden after page-load without running into hiding/showing not working and without having to resort to !important.

    A more elegant solution to your issue, I’d say.

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

Sidebar

Related Questions

I have a little HTML5 web app for mobile devices (running inside PhoneGap/Cordova). I
I have a little temperature protocoling web app, where degrees get adjusted on a
I'm a beginner with Zend. I have a little web site in which I
I am a little confused about Accept-Encoding . I have Web Service which would
We have a load balanced (NLB) ASP.NET web app which sends email. The servers
I have an asp.net MVC web app that processes images and resizes them which
I have a little web app that uses the Facebook like widget. This page
I am adding ajax to this little list web app I made. I have
I have an app in which I have a lot of references and the
I have a little POC web app that I'm putting together, and one of

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.