[Opa] onload focus()

Owen Gunden ogunden at phauna.org
Wed Jan 18 18:29:28 UTC 2012


On Wed, Jan 18, 2012 at 2:37 AM, Nicolas Glondu
<nicolas.glondu at mlstate.com> wrote:
> Le 18/01/2012 04:10, N Owen Gunden a écrit :
>
>> What's the best way to achieve this in opa?
>>
>>   function init() {
>>     document.getElementsByTagName('input')[0].focus();
>>   }
>>   window.onload = init;
>>
>> (it can also be done with<body onload="...">)
>
> Here is how (in the old syntax) :
>
> <div onready={_ -> Dom.give_focus(Dom.select_raw(input:first))}>...</div>
>
> This will give focus the first input in the page (like your code). You can
> of course use another selector, put this in a separate initialization
> function or use something else than a div.

Awesome, it works perfectly. Thanks!


More information about the Opa mailing list