Solved

Jquery dive hide-show problem

Posted on 2010-11-16
5
723 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

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

In this article you'll learn how to use Ajax calls within your CodeIgniter application. To explain this, I'll illustrate how to implement a simple contact form to allow visitors to send you an email through your web site.
How to build a simple, quick and effective accordion menu using just 15 lines of jQuery and 2 css classes
The viewer will learn how to dynamically set the form action using jQuery.
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…

717 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