Can the focus()
function be used on an input field that is located inside a hidden div with the following CSS properties:
opacity: 0;
visibility: hidden;
When a button is clicked, the hidden div becomes visible by adding a new class to the body:
Check out the demonstration here: http://jsfiddle.net/yyd1pgaa/
It seems that if the transition effects are removed, the focus()
function works. Could this be because browsers are unable to focus on elements that are not fully visible?
Is it possible to achieve this functionality without relying on the use of setTimeout()
?