I am creating a web site for a college outcome and I have made a button that when clicked performs a JavaScript function to increase the height of a HTML div and when the button is no longer hovered over, the size decreases. However I would like to know if and how I could make it so when the height is more if i click the button again the height will go to less. I believe a global variable could be used? but i'm not the most confident with JavaScript. I've attached the code below for my script. I haven't had any errors, it works as expected, I would just like to take a different approach to the solution for ease and aesthetics.
function showmoreinfo() {
var x = document.getElementById("road");
x.style.height = "600px";
showlessinfo();
}
function showlessinfo() {
var x = document.getElementById("road");
x.style.height = "430px";
}
<button onmouseout="showlessinfo()" onclick="showmoreinfo()" class="moreinfo"><i class="fa fa-arrow-down"></i></button>
FYI, 430px is the default hide of my div!
Any feedback is welcome!