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

The Archive Base Latest Questions

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

I have a script that hides a div by default and slideToggles it when

  • 0

I have a script that hides a div by default and slideToggles it when I click a link (see http://zarin.me — the contact link). Here’s the code I’m using:

<script>
$(document).ready(function(){
    $("#contact-drawer").hide();
    $(".toggle-drawer").show();

    $('.toggle-drawer').click(function(){
    $("#contact-drawer").slideToggle();
}); 
});
</script>

My problem is that when the page loads, the whole div is displayed for a split second, and then hidden. This can be a bit a jarring sometimes. What do I need to fix so that the div doesn’t display on load?

  • 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-06T08:17:15+00:00Added an answer on June 6, 2026 at 8:17 am

    As Darko Z said below, the reason for this flickering is that there is a delay between the browser rendering the #contact-drawer element and your JavaScript code running. The browser is doing what it’s told by your CSS and HTML and displaying the element, and only after that is it indicating the document has finished parsing (DOM ready) and triggering your JavaScript.

    There are a few ways to fix this (with varying compatibility). Essentially you need to get code interpreted in between or before the element rendering and the DOM being ready.

    To patch with JavaScript, you could add an inline script immediately after the element to set it’s display to hidden. This code would be executed immediately as the page is interpreted rather than when the DOM is ready. I believe this is the simplest and safest method in terms of accessibility.

    Plain JavaScript:

    <section id="contact-drawer"></section>
    <script>document.getElementById('contact-drawer').style.display = 'none';</script>
    

    or with jQuery:

    <section id="contact-drawer"></section>
    <script>$("#contact-drawer").hide();</script>
    

    To fix with pure CSS you would set the element’s display property to ‘none’. Note that with this solution, if JavaScript is disabled the form will not be accessible.

    CSS

    #contact-drawer {
        display:none;
    }
    

    To fix with CSS AND maintain a working page when javascript is disabled you could use an additional :target CSS selector and change your link and JavaScript a little. The target selector is not 100% compatible with older browsers, but it’s more accessible than the plain CSS version above.

    CSS

    Add the same style as above, and a copy setting display to block with the selector :target. This makes it so when you navigate to http://zarin.me/#contact-drawer, the :target style will activate and #contact-drawer will display.

    #contact-drawer {
        display:none;
    }
    #contact-drawer:target {
        display:block;
    }
    

    HTML

    Change the anchor href from # to #contact-drawer so that when the link is click, it activates the :target selector.

    <h3 class="contact">
        <a href="#contact-drawer" class="toggle-drawer" style="">
            <img src="img/envelope.png">
            CONTACT
        </a>
    </h3>
    

    JavaScript

    Add return false at the end of the function to stop the browser navigating to #contact-drawer (and activating the :target selector) when .toggle-drawer is clicked.

    $('.toggle-drawer').click(function(){
        $("#contact-drawer").slideToggle();
        return false;
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some JQuery code that shows or hides a div. $(div#extraControls).show(); // OR
I have a simple jquery script that shows and hides div block: <script type=text/javascript>'
I have a script that connects to SQL Server 2005 default instance. But I'm
http://img175.imageshack.us/img175/4295/tableissue.png http://img175.imageshack.us/img175/4295/tableissue.png Here's the picture to begin with. I have this check box, that
I have the following script, which when you click the image within the div,
I have a script that populates that hides and shows divs based on whether
I have a script that will slide a div up from the bottom of
I have a little script that shows a div when an arrow is clicked.
I have the following code: <html> <head> <script src=http://ajax.googleapis.com/ajax/libs/jquery/1.5/jquery.min.js></script> <script> $(document).ready(function() { // hides
I have some jQuery that hides half a div that contains an image and

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.