Put your javascript right under the input field.

<form name="myForm" ...>
<input id="username" name="username" ... />
...
</form>
<script>
document.myForm.username.focus();
</script>

It is not jQuery, but plain javascript. Just in case jquery is not
fully loaded...

jQuery HowTo Resource  -  http://jquery-howto.blogspot.com



On Fri, Jan 9, 2009 at 6:25 PM, Gordon <gordon.mc...@ntlworld.com> wrote:
>
> I've got a field on a web page that needs some javascript behaviour
> when it gains or loses focus, so I attached the appropriate handlers
> in a $(document).ready to the field.
>
> It all works fine, except if the user focuses the input field before
> the ready event fires.  In this case the behaviour doesn't occur.
>
> The old version used onfocus and onblur attributes in the tag itself,
> which is obviously a very bad way of doing it, but did have the
> advantage that the behaviour would occur as soon as the input field
> became visible.
>
> Is there a friendlier way of attaching behaviour before the ready
> event?

Reply via email to