Anant
Anant

Reputation: 59

.show() not showing HTML element

Here the problem: the layer gets sucessfully hidden, but when I click the button again, it won't re-appear. Any ideas?

<head>
    ...
    <script type="text/javascript" 
        src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js">
    </script>

    <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>

Upvotes: 0

Views: 83

Answers (1)

meder omuraliev
meder omuraliev

Reputation: 186562

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.

Upvotes: 3

Related Questions