Solved

Jquery dive hide-show problem

Posted on 2010-11-16
5
719 Views
Last Modified: 2012-06-27
Hello,
I am new to jquery and is trying the following code

HTML
=====

<a class="toggle" href="#">Statement</a>
<div id="progressBar" >
    <p> Loading ... </p>
</div>    
<div id="taxStatement" >
    <p>Hi</p>
</div>

Javascript
=========
$(document).ready(function(){
    progressBar.hide();
    taxStatement.show();
   
}
);

But it is not hiding progressBar div and it supposed to show taxStatement div.

Thanks!


0
Comment
Question by:dojjol
5 Comments
 
LVL 12

Accepted Solution

by:
JESii earned 125 total points
ID: 34149691
You have to start out with style="display:none" hard-coded on the element you want to show/hide, otherwise it doesn't work.
0
 
LVL 82

Assisted Solution

by:leakim971
leakim971 earned 250 total points
ID: 34149698
You need to use : $("#idOfTheControl").hide()
$(document).ready(function(){
    $("#progressBar").hide();
    $("#taxStatement").show(); // please note it is not hidden in your current page... should be <div id="taxStatement" style="display:none" >
});

Open in new window

0
 

Author Comment

by:dojjol
ID: 34150013
Thanks but if I modify the ready function to

$(document).ready(function(){
    $("#progressBar").show();
    $("#taxStatement").hide();
    for(var i=0 ; i<1000; i++)
        {
            $("#taxStatement").html("<p>"+i+"</p>")
        }
           $("#progressBar").hide();
        $("#taxStatement").show();
}
);

it directly prints taxStatement div instead of first displaying progressBar div and then taxStatement div
0
 
LVL 82

Assisted Solution

by:leakim971
leakim971 earned 250 total points
ID: 34150493
Replace all your code by :

setTimeout('$("#progressBar").show();$("#taxStatement").hide();', 3000);

Open in new window


Please wait three seconds
0
 
LVL 6

Assisted Solution

by:mickey159
mickey159 earned 125 total points
ID: 34153002
To dojjol:
This is because the javascript engine is too fast that the for loop you created used less than a second to finish.So the progressBar don't even have the chance to load.

The code should be like this:
I changed the show() and hide() to fadeIn() and fadeOut() to have more visual effects.
Hope you don't mind.
Please don't change fadeIn() and fadeOut() with show()and hide() or it may not work.

Good luck!
$(document).ready(function(){
    $("#progressBar").show();
    $("#taxStatement").hide();
    for(var i=0 ; i<1000; i++)
        {
        $("#taxStatement").html("<p>"+i+"</p>")
        }
        $("#progressBar").delay(2000).fadeOut(500);
        $('#taxStatement').delay(2500).fadeIn(500);
}
);


//full code for testing
<html>
<head>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.4.4.js"></script>
<script type="text/javascript">
$(document).ready(function(){
    $("#progressBar").show();
    $("#taxStatement").hide();
    for(var i=0 ; i<1000; i++)
        {
        $("#taxStatement").html("<p>"+i+"</p>")
        }
        $("#progressBar").delay(2000).fadeOut(500);
        $('#taxStatement').delay(2500).fadeIn(500);
}
);
</script>
</head>
<body>
<div id="progressBar">
    <p> Loading ... </p>
</div>    
<div id="taxStatement">
    <p>Hi</p>
</div>
</body>
</html>

Open in new window

0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
count download link and run update query 9 55
JS Plugin Chaining 2 32
Clear single text form value in jquery 2 29
Redirect Website for Mobile Devises 7 24
What is a Lightbox? A Lightbox is the effect you see when you click, for example, an image and the screen fades out and up pops the same image but in its full size dimensions. There are lots of Lightbox effects for jQuery. Problem is they are a…
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now