Javascript else condition not triggering
<p>I am trying to do a basic javascript/jquery animation. Basically, a div that is hidden under normal view, should come into view when clicking a button.</p>

<p>The problem I have is in the condition (the <code>if else</code> statement).</p>

<p>Here is the code that I am using.</p>

<pre><code>$(document).ready(function () {
    animationClick('#animateThis', '#someElement', '#startHere');
});

function animationClick(element, secondElement, elementToBeClicked) {
    element = $(element);
    elementToBeClicked = $(elementToBeClicked);
    secondElement = $(secondElement);
    var state = 0;
    var containerWidth = $('#container').width();
    elementToBeClicked.on("click", function () {
        if(state == 0) {
            secondElement.animate({
                top: '27%',
            }, 500);
            element.animate({
                left: '0%',
            }, 500);
            elementToBeClicked.html("Hide");
            state = 1;
        } else {
            alert('hehehe');
        }
    })
};
</code></pre>

<p>So, basically, this is what happens. The whole function is put into document.ready. When I click on the button (which this function is bonded to),the <code>if</code> statement returns <code>true</code>, and the code gets executed. It also sets the state to <code>1</code>.</p>

<p>After the state gets set to <code>1</code>, the <code>else if</code> statement should come into action and show an <code>alert("hehehe")</code>, but it does not. </p>

<p>Can anyone give me some kind of an advice? What am I doing wrong ?</p>
