Solved

Jquery dive hide-show problem

Posted on 2010-11-16
5
721 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Make Session back to empty 9 30
jQuery when a text link is clicked? 16 37
Json Schema 8 32
Html input text color the frame line 2 20
Requirements JQuery 1.6+ HTML CSS Introduction This article was inspired by an EE question (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28372511.html) on how to make a page show some balloons animate up a page…
Introduction Chart.js, used properly, can visually add a difference to your charting applications. It engages your visitors and allows them to interact with data they otherwise wouldn't be able to without expensive and complicated systems. For this…
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)

809 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