1

I have an array set up that has something added to the array every time to drop a word into a bucket on the page. I'm trying to show and hide certain div's depending on how many objects are in the array.

My code is:

if (test > 5){
    $(".moving").hide();
    $("#done").show();
}

This works perfectly except when the page first loads. The div with ID #done is still showing when the page first loads and then goes away when the array gets it's first object. (Array starts empty)

2
  • is test = number of objects in the array? Commented May 3, 2016 at 16:52
  • Can you please show more code or create a jsFiddle? Commented May 3, 2016 at 16:52

5 Answers 5

3

In your css just add #done{display: none;} That way the div will not show when page first loads.

Or use #done{visibility: hidden;} if you just want the div not to be visible.

Sign up to request clarification or add additional context in comments.

1 Comment

Perfect. Thank you!!
0

If you don't have access to the HTML code you could hide it in ready function :

$(function(){
    $("#done").hide();
    //Or
    $("#done").css("display","none");

    //The rest of code
});

Hope this helps.

Comments

0

Use : #done{display:none;} or #done{opacity:0;}

Later in code, whenever you want to display it, you may use js/css to change display to block or opacity to 1.

Comments

0

The following function will hide done div and show moving div when page is ready after complete page is rendered:

$(document).ready(function(){
  $("#done").hide();
  $(".moving").show();
});

Similarly you can use load method in to run a function on page load. but be aware load method is executed before complete page is rendered

Comments

0

In your current code, you can add the following at the very beginning of ready function,
$('#done').hide();
or
$('#done').css('visibility','hidden');

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.