My application allows users to click a button that triggers the appearance of a text field using ajax.
After the text field appears, I am attempting to focus on it.
Interestingly, $("#my-textfield").focus()
works perfectly when executed in the console, but fails to work when placed in my js.erb file. Even trying it with a setTimeout
did not yield the desired results.
When attempting
document.getElementById('my-textfield').focus();
, I encounter an error message stating "cannot focus on null".
Is there a need to somehow "reload" the DOM after loading a partial through ajax?