SIGN UP MEMBER LOGIN:    
ARTICLE

slideToggle() in jQuery

Posted by Praveen Kumar Articles | ASP.NET MVC with C# March 18, 2011
Here I am going to explain slideToggle() method in jQuery.
Reader Level:
Download Files:
 

jQuery slideToggle() method helps us to hide and show the matched elements. This is when the lower portion of the element slides up and down the page. 


This is very useful in hiding and showing the controls on click.

Here in this article I am showing a simple example to show/hide a div using this method.

In a simple HTML page, I have designed something like this:

<div id="prelogin" class="prelogindiv">Login</b></div>
<div id="login" class="logindiv" >
      Username:  <input id="Text1" type="text" /></p>
    <p>
        Password: <input id="Password1" type="password" /></p>
            <p>
        <input id="Button1" type="button" value="Login"/></p>
</div>

Defined styles for the two div I have used in the code above.

<style>
.prelogindiv
{
background:#cc99ff;
width:200px;
height:20px;
}
.logindi
{
background:#8CC43F;
width:200px;
height:150px;
}
</style>

Now in the onload event of the page I have called a javascript function to hide the second div.

<body onload="javascript:divcolp();">

<script language="javascript">
    function divcolp() {
        $("#login").hide();
    }
</script>

Now in the onclick event of the div tag I am showing/hiding the div tag.

<script language="javascript">
    function slideDiv() {
       $("#login").slideToggle();              
    }
</script>

Hence, when the div is visible and if we click on first div, second div will hide and vice versa.

Login to add your contents and source code to this article
share this article :
post comment
 
6 Months Free & No Setup Fees ASP.NET Hosting!
Become a Sponsor
PREMIUM SPONSORS
  • ceTE software specializes in components for dynamic PDF generation and manipulation. The DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and new content to existing PDF documents from within your applications. Visit DynamicPDF here
    Finally – a virtual platform that delivers next-generation Windows Server 2008 Hyper-V virtualization technology from a managed hosting partner you can truly depend on. Visit www.maximumasp.com/max for a FREE 30 day trial. Hurry offer ends soon. Climb aboard the MaxV platform and take advantage of High Availability, Intelligent Monitoring, Recurrent Backups, and Scalability – with no hassle or hidden fees. As a managed hosting partner focused solely on Microsoft technologies since 2000, MaximumASP is uniquely qualified to provide the superior support that our business is built on. Unparalleled expertise with Microsoft technologies lead to working directly with Microsoft as first to offer IIS 7 and SQL 2008 betas in a hosted environment; partnering in the Go Live Program for Hyper-V; and product co-launches built on WS 2008 with Hyper-V technology.
Become a Sponsor