Hide and Show A div using toggle() method

<!–

using toggle() method we can short out the whole code. In this code when we run the code it will first work on the first function that is hide out the div and make the anchor text in show.
Then when we click second time it will work on the second callback funtion because before click it worked on the first callback function. So click after click it will work like a loop between first function and second function ..

 –>

<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”&gt;
<html xmlns=”http://www.w3.org/1999/xhtml”&gt;
<head>
<meta http-equiv=”Content-Type” content=”text/html; charset=utf-8″ />
<title>Untitled Document</title>
<style type=”text/css”>
#tom
{
background-color:#CCC;
border:1px solid #0FF;
height:100px;
width:200px;
}
</style>
<script type=”text/javascript” src=”jquery.js”></script>
<script type=”text/javascript”>

$(document).ready(function(){

$(‘#link’).toggle(function(){

$(this).text(“Show”);
$(‘#tom’).hide();

},function(){

$(this).text(“Hide”);
$(‘#tom’).show();

});

});

</script>
</head>

<body>
<a href=”” id=”link”>Hide</a>
<div id=”tom”>

You know something! that you want to know but what you dont know is that don’t want to know.
So what you know share then you will not forget .. :-))

</div>
</body>
</html>

Advertisements
By kfelahi Posted in JQuery

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s