Hello everyone, first of all I’m new here so apologies if my post and or formatting is incorrect or wrongly placed. I have a simple website that I’ve created to provide information with an accordion style show/hide list of headers. I’ve cobbled together some javascript in to it to allow the sections to expand dynamically to the correct length as the content is different for each of them.
Javascript:
function showhide(input) {
var box = document.getElementById(input);
if (box.style.height > "30px") {
box.style.height = "30px";
} else {
var x = document.getElementsByClassName("display");
var i;
for (i = 0; i < x.length; i++) {
x[i].style.height = "30px";
}
var boxsize = (box.scrollHeight) + "px";
box.style.height = boxsize;
}
}
Basically, if the section which has been clicked is already open, it should close.
If it is not already open, it should close the one that is currently open and then open itself.
This works fine for the purpose I’m using it for however I’m seeing an issue where if the content is larger than 100px, the script no longer allows it to close itself. It will close fine if another section is opened but clicking the open section to close itself does not work. I’ve tested it by making a section 99px which still closes without issue and then making it 100px and it no longer does. My JavaScript knowledge isn’t great so I’m hoping I’m missing something obvious. Hoping someone can help.
I’ve tried to upload a copy of the HTML file however as my account is new, I’m unable to do so.