vendredi 25 janvier 2019

OnClick if statement only running once?

I have an issue with an if statement that is being called when the user clicks on an element. Below is the code of said element:

<div id="dropdown" onclick="dropper()" class="YearEvents_2016">
    <h1>2016</h1>
</div>

the function "dropper()" code:

function dropper() {
    var x = document.getElementById('dropdown');
    var y = document.getElementById('YearEvents');
    if (x.style.height = "14vh") {
        x.style.height = "75vh";
        y.style.height = "100vh";
    } else {
        x.style.height = "14vh";
    }
}

When the user clicks the element, the code runs and the x and y variables are changed. However, upon clicking the element again (in order to reduce the x variable's height back down to 14 again) nothing happens, despite the else part of the statement depicting that something should happen.

Not sure if its something completely obvious; I'm not that advanced in Javascript. Any help as to why the function doesn't run again when the element is clicked on again, would be greatly appreciated.

Aucun commentaire:

Enregistrer un commentaire