Solved

Jquery dive hide-show problem

Posted on 2010-11-16
5
718 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Introduction HyperText Transfer Protocol (http://www.ietf.org/rfc/rfc2616.txt) or "HTTP" is the underpinning of internet communication.  As a teacher of web development I have heard many questions, mostly from my younger students who have come to t…
PROBLEM: The other day I was working on adding an ajax request to a webpage that already had a dialog box on the page.  The dialog box was using relative positioning to be positioned next to a form field I had on the page.  Everything was working…
The viewer will learn how to dynamically set the form action using jQuery.
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)

771 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

9 Experts available now in Live!

Get 1:1 Help Now