Monday, 12 March 2012
























Create two file
1. hide.js
2. hide.html


In  hide.js file  add the following code


$(document).ready(function() {

    $(".btn-slide").click(function() {
        $("#panel").slideToggle("slow");
        $(this).toggleClass("active");
        return false;
    });


});

In  hide.html file  add the following code



<html>
<head>
<title>jQuery Hello World </title>
<script type="text/javascript" src="jquery-1.4.2.js"></script>
<script type="text/javascript" src="hide.js"></script>

    <style type="text/css">


    body
        {
            margin: 10px auto;
            width: 570px;
            font: 75%/120% Arial, Helvetica, sans-serif;
        }
       
        a:focus {
outline: none;
}
#panel {
background: C5C841;
height: 200px;
display: none;
}
.slide {
margin: 0;
padding: 0;
border-top: solid 4px #422410;
background: url(images/btn-slide.gif) no-repeat center top;
}
.btn-slide {
background: url(images/white-arrow.gif) no-repeat right -50px;
text-align: center;
width: 144px;
height: 31px;
padding: 10px 10px 0 0;
margin: 0 auto;
display: block;
font: bold 120%/100% Arial, Helvetica, sans-serif;
color: #fff;
text-decoration: none;
}
.active {
background-position: right 12px;
}



    </style>

</head>



<body>


<div id="panel">
//your code here
</div>

<p class="slide"> <a href="#" class="btn-slide"> Panel</a></p>

</body>


</html>


Hide the image using toggle function


Create two file
1.slide.js
2. slide.html


In  slide.js file  add the following code

$(document).ready(function(){

$('#imgplus').toggle(
               function() {
                var srcValue = "images/tall-up-arrow.gif"
                $('#imgplus').attr('src', srcValue);
                $('#panel').hide('fast');

            },
            function() {
                var srcValue = "images/tall-down-arrow.gif"
                $('#imgplus').attr('src', srcValue);
                $('#panel').show('fast');
            }
         
            );


});

In  slide.html file  add the following code



<html>
<head>
<title>jQuery Hello World </title>
<script type="text/javascript" src="jquery-1.4.2.js"></script>
<script type="text/javascript" src="slide.js"></script>
</head>



<body>


<img src="images/tall-down-arrow.gif" id="imgplus"  />
<div id="panel">
<p id="message">you can see this </p>
</div>


</body>


</html>


Hide the Button using click event



















Create two file
1. hide.js
2.hide.html


In  hide.js file  add the following code

$(document).ready(function(){
$('#cl').click(function(){
var value=$('#cl').attr('value');
$('#message').toggle('fast');

if (value=='hide'){
$('#cl').attr('value','show');
}
else if (value=='show'){
$('#cl').attr('value','hide');
}
});
});

In  hide.html file  add the following code



<html>
<head>
<title>jQuery Hello World </title>
<script type="text/javascript" src="jquery-1.4.2.js"></script>
<script type="text/javascript" src="hide.js"></script>
</head>



<body>

<input type="button"  id="cl" value = "hide" />
<p id="message">you can see this </p>
</body>


</html>