hide method in jQuery with example

1. hide() method is used to hide the elements.
2. hide() with no duration is equivalent to css property 'display : none'.
3. hide(200) with duration specified becomes animation method.
4. Duration is given in milliseconds, and slow and fast string indicates 600 and 200 milliseconds respectively.

Example 1 :

        <title>hide in jQuery</title>
        <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"> 
        <script type="text/javascript">
            $(document).ready(function () {
                $("#buttonHideNormal").click(function () {

                $("#buttonHideAnimation").click(function () {
                    $("#form").hide("slow", function () {
                        alert("hide with duration slow !!");
                $("#buttonShow").click(function () {
        <fieldset id="form">
        <td><input type="text" id="txtName"><td>
        <td><input type="text" id="txtAge"><td>
        <td><input type="text" id="txtAddress"><td>
        </fieldset><br />
        <div id="buttonDiv">
        <input type="button" id="buttonHideNormal" value="Hide Normal"/>
        <input type="button" id="buttonHideAnimation" value="Hide Animation"/>
        <input type="button" id="buttonShow" value="Show"/>
Demo :

In the above example, we have used hide() method. When we click the "HideNormal" button, it will hide the form like 'display : none' css property.
        There is no animation involved, as we have not specified duration. When we click on "HideAnimation" button it hides the form with animation effect as duration for hiding is specified.


Post a Comment