Within my HTML code, there is a group of input
elements nested under another group of div
elements. I have a button that, when clicked, toggles the display of one of the input elements from hidden to visible using JavaScript:
if (switched) {
document.getElementById("div-xxx").style.display = "block";
}
Now, I am wondering if there is a way to automatically focus on the input element within the displayed div
after it becomes visible. I attempted to achieve this by adding the following line of code right after the display toggle:
document.getElementById('input-xxx').autofocus = true;
Despite including this autofocus attribute, the input field does not automatically gain focus as intended.