jeudi 21 janvier 2016

vanilla js onclick if statement issue

I'm attempting to affect a change to an elements height when another element is clicked. I'm using an if else statement in order to toggle the change back and forth.

var bnr = document.getElementById("bnr");
var btn = document.getElementById('btn');

if (bnr.style.height = "250px")
{ 
btn.onclick = function() {
  bnr.style.height = "600px";
};
}   

else if(bnr.style.height = "600px")
{ 
btn.onclick = function() {;
  bnr.style.height = "250px";
};
};

The first statement works, changing the elements height to 600px however the second statement isn't working and the element stays at 600px if you click again.

Is anyone able to see where I am going wrong here?

JS Fiddle example

Aucun commentaire:

Enregistrer un commentaire