I wanna to do scroll down to next div by pressing button on pure JS. But this code:
var hiddenElement = document.getElementById("box");
var btn = document.querySelector('.btn');
function handleButtonClick() {
hiddenElement.scrollIntoView({block: "center", behavior: "smooth"});
}
btn.addEventListener('click', handleButtonClick);
.big {
background: #ccc;
height:100vh;
}
.btn {
font-size: 14px;
}
.box {
background: lightgreen;
height: 100vh;
}
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script src="script.js"></script>
<title>Document</title>
</head>
<body>
<button type="button" class="btn">Press</button>
<div class="big"></div>
<div id="box" class="box">Hidden Block</div>
</body>
</html>
didn't work when i opened it on my PC BUT it is working on JSfiddle. Why? Here is the link: jsfiddle
`, or [read this](https://developer.mozilla.org/en-US/docs/Web/API/Window/DOMContentLoaded_event), for jQuery [read that](https://learn.jquery.com/using-jquery-core/document-ready/).
– skobaljic Apr 20 '20 at 09:46