Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums JavaScript height reduced when clicked Re: height reduced when clicked

#105788
JoeBass
Member

Thanks for your replies guys but I am actually looking for a raw Javascript solution. Doing it with jQuery wasn’t a problem. I am just learning pure Javascript to up my chances at advancement within the companu I work for. What I currently have is:

HTML:

open box

hola

Javascript:
var box1 = document.getElementById(“box”);
var box2 = document.getElementById(“boxtop”);

box2.offsetHeight;

box1.onclick = function fade() {
setInterval(function() {
box2.style.height -= 20 + “px”;
console.log(box2.offsetHeight);
}, 200);
}

The console.log is in there to track the size as it subtracts over time but it just spits the set height, which is 200px. I got this to work with just opacity on the first try and the console.log displays lesser value overtime. Why wouldn’t work with height? Didn’t think there would be a difference.