Edit: If you have not developed on Windows 8, do not try to answer this question. Do not vote on it. Do not even read it. This is not a web app or website and does not run in a browser. Please stop down-voting content you do not understand. This is a Windows 8 METRO HTML5/js application that runs in the Windows Runtime environment.
Original Question:
I want the cursor to be "blinking" in the input box, ready to receive input. I'm using javascript to set the focus. This isn't working:
document.querySelector("#input-box").focus();
Anyone know why? Is the focus method not the correct one to use for this?
Thank you.
Edit #2: So it definitely has something to do with the fact that I am trying to set focus to the input from a ListView's "itemInvoked" event. The event is firing properly, the element is accessible from the event handler, and the line has no errors on execution. I can set focus to my input tag from a standard button click event, but not from an ItemInvoked event. So the question is, why can't I set focus from within this event handler?
autofocus
attribute. – Bionomicsdocument.querySelector("#input-box").focus();
twice. #2: If #1 fails, try calldocument.querySelector("#input-box").select();document.querySelector("#input-box").focus();
. #3: If #2 fails, put the focus inside a timeoutsetTimeout(function(){ document.querySelector("#input-box").focus(); }, 100);
. I KNOW is WinRT but i just covered some focus() bugs that happened on IE9. Testing does not hurts, right? – Upthrow