Is there a way to resize a div based on the user's decision to hide or show specific content? For example, take a contents page like this one (https://jsfiddle.net/4b1g5jp9/1/). When a user clicks 'hide', I want the div to adjust its size accordingly by hiding all content except for the actual Contents title.
In addition, I only want the 'Show' link to appear if the content is hidden and vice versa.
I attempted to modify some JavaScript code from a similar issue I found online. Here is what I tried:
<script language="javascript">
function toggle() {
var ele = document.getElementById("contents-list");
if (ele.style.display == "block") {
ele.style.display = "none";
} else {
ele.style.display = "block";
}
}
</script>
However, the above solution did not work as expected. Any advice or alternative solutions would be greatly appreciated.