I have an HTML along the following lines:
<div class="hiddenClass"> // this implies display:none
<span>
<input type="text" id="hiddenInput"/>
</span>
</div>
and a Javascript event (triggered in a "succes" method of an jQuery $.ajax() call ), that needs to make this div visible and then set the focus to the control. Something like:
this.DOMElements.divElement.className="showClass"; //a CSS class with display:block;
this.DOMElements.hiddenInputElement.focus();
this.DOMElements.hiddenInputElement.select();
strange enough, this code only works part of the time. In some cases (only sometimes!!) the focus/select commands generate warnings about focusing/selecting an invisible control. The control will be made visible, but the focus is not moved, nor is the text selected.
I found (somewhat) of a solution by moving the focus/select code in a separate function and delay-call it by means of a
this.DOMElements.divElement.className="showClass"; //a CSS class with display:block;
setTimeout("focusinput('hidddenInput')",1);
Ok, finally my question: since javascript is single-threaded.. how come there is a delay between the time I made the parent div visible, and the time I can set the focus/select on the child input element ? How could this be a race condition?
Edit: Happens in IE8