Struggling a bit here and need some help. I have three buttons and three hidden divs. When a button is clicked, the hidden content appears. How can I automatically scroll down so that the revealed content starts at the top of the page?
<script type="text/javascript">
function showDiv(num) {
document.getElementById('div1').style.visibility='hidden';
document.getElementById('div1').style.height='0px';
document.getElementById('div1').style.overflow='hidden';
document.getElementById('div2').style.visibility='hidden';
document.getElementById('div2').style.height='0px';
document.getElementById('div2').style.overflow='hidden';
document.getElementById('div3').style.visibility='hidden';
document.getElementById('div3').style.height='0px';
document.getElementById('div3').style.overflow='hidden';
document.getElementById('div'+num).style.visibility='visible';
document.getElementById('div'+num).style.height='10px';
document.getElementById('div'+num).style.overflow='visible';
}
</script>
My CSS:
#div1, #div2, #div3 {
visibility: hidden;
height:0px;
overflow:hidden
}
.button {
background-color: green;
border: none;
color: white;
padding: 15px 32px;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 22px;
cursor: pointer;
font-family: Arial;
}
My buttons:
<input type="button" class="button" name="Showdiv1" value="Show Div 1" onclick="showDiv('1')" />
<input type="button" class="button" name="Showdiv2" value="Show Div 2" onclick="showDiv('2')" />
<input type="button" class="button" name="Showdiv3" value="Show Div 3" onclick="showDiv('3')" />
<div id="div1"> I'm div1 </div>
<div id="div2"> I'm div2 </div>
<div id="div3"> <form style="margin-top:1000px;height: 1000px;" id="form1">
Form with huge data in it
</form> </div>
A demonstration where div 3 contains a lengthy form that begins lower on the page: https://jsfiddle.net/cgrouge/Lx0pyg4L/