views:

28

answers:

1
<!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=iso-8859-1" />
<title>Shout!</title>

<script type="text/javascript"  src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"&gt;&lt;/script&gt;

<script type="text/javascript">


function action() {

var status;
status=1;

if(status==1) {
$("#Layer1").hide("slow");

 $("#close").attr("src","open.jpg");
status=0;

}

else if(status==0) {
status=1;
$("#Layer1").show("slow");

$("#close").attr("src","close.jpg");

}


}
</script>
<style type="text/css">
<!--
body {
background-color: #000000;
}
#Layer1 {
position:absolute;
width:200px;
height:115px;
z-index:1;
left: 179px;
top: 3px;
}
#Layer2 {
position:absolute;
width:101px;
height:80px;
z-index:2;
left: 570px;
top: 473px; 
}
-->
</style></head>

<body>
<div id="Layer1"><img src="body.jpg" width="842" height="554" /></div>
<div id="Layer2"><img src="close.jpg" id="close" width="63" height="64"     OnClick="action()"/></div>
</body>
</html>

Here the problem is that the layer gets sucessfully hidden.But when i click the button again,it wont re-appear ! Any ideas?

Thanks!

+2  A: 

Define status outside the action function, otherwise it starts off with 1 every time.

var status = 1; function action(){}

Provided your logic is right, this should work.

meder