In a single function, I'm trying to achieve 2 things :
- Scroll to a section
- Focus on an input
This is my code :
function search() {
document.getElementById("searchbar").style.display = "block";
document.getElementById("flex").style.display = "none";
document.getElementById("books").scrollIntoView({behavior: 'smooth'});
key();
};
function key(){
document.getElementById("searchbox").focus();
};
The scrolling is not working here. If i remove the 'key' function, it works.
There's no need for separate 'key' function, but i tried.
The input with id "searchbox" is placed inside a "position:fixed" division. Its outside the "books" section.