what i am trying to do is, if text box have some value page should move to center div, when text box is empty page should stay on start position.
in my code page always goes to second div.
$(document).ready(function() {
if ((document.getElementById("textbox").value != null)) {
// Handler for .ready() called.
$('html, body').animate({
scrollTop: $('#what').offset().top
}, 'slow');
}
});
div {
height: 900px;
border: 2px solid #333;
padding: 10px;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<input type="text" id="textbox" />
<div id="mydiv">DATA FOR SAMPLE 1</div>
<div id="what">SAMPLE DATA</div>
valueis always an empty string if it's not filled in. Even if the attribute is missing.