What is the proper method to set the focus to a specific field within a dynamically loaded DIV?
$("#display").load("?control=msgs"); // loads the HTML into the DIV
$('#display').fadeIn("fast"); // display it
$("tex#header").focus(); // ?? neither that
$("input#header").focus(); // ?? nor that
$('#display', '#header').focus() // ?? nor that
$("#header").focus(); // ?? nor that works
The following HTML is fetched into the display
DIV:
<div id="display">
<form id="newHeaderForm" class="dataform" action="/" method="post">
<input id="to" type="hidden" value="22" name="to"/>
<dl>
<dt>Header</dt>
<dd>
<input id="header" class="large" type="text" name="header" value="" maxlength="128"/>
</dd>
</form>
</div>
Many, many thanks!
most of error are because U use wrong object to set the prorepty or function. Use console.log(new_fild); to see to what object U try to set the prorepty or function.
As Omu pointed out, you must set the focus in a document ready function. jQuery provides it for you. And do select on an id. For example, if you have a login page:
If
is not working then is there another element on your page with the id of header?
Use firebug to run
$("#header")
and see what it returns.Dynamically added items have to be added to the DOM...
clone().append()
adds it to the DOM... which allows it to be selected via jquery.Have you tried simply selecting by Id?
Seeing as Ids should be unique, there's no need to have a more specific selector.