Skip to content

Instantly share code, notes, and snippets.

@samedhi
Last active December 15, 2015 23:29
Show Gist options
  • Save samedhi/5340681 to your computer and use it in GitHub Desktop.
Save samedhi/5340681 to your computer and use it in GitHub Desktop.
I am trying to grab a id="search-box" element and give it focus. I do get "I was able to grab it!" with the code below. Unfortunately, the search-box element in question does not get focus. To be clear, the search-box is on the initial (on-load) page. The search-box element is in template code. Is on-load too early for elements that are rendered…
window.onLoad.listen((Event e){
Element elem = query("#search-box");
if(elem != null){
print("I was able to grab it!");
elem.focus();
}else{
print("I was not able to grab the element");
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment