How can i scroll the page to the bottom when i use javascript focus on page load?
$(".answer-input").focus();
if( $(".alert-error") != [] ){
window.scrollTo(0, document.body.scrollHeight);
}else{
window.scrollTo(0, 0);
}
The problem is that there is no .alert-error on page the page is still scrolled to the bottom. What am i doing wrong?
jQuery returns an empty array if it does not find any matching element but that is not the way to compare an empty array. Use
lengthproperty of the arrar to check if it is 0 or not.