[Opa] onload focus()

Nicolas Glondu nicolas.glondu at mlstate.com
Wed Jan 18 07:37:12 UTC 2012


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.

-- 
Nicolas Glondu


More information about the Opa mailing list