I have an input
<input type='text' id='email'/>
For some event I'd like to focus on that textbox
$('#email').click()
But this code doesn't work for some reasons (Chrome). How can I achieve my goal?
Instead of click you should use focus() to have a focus on the desired target element and make sure to wrap it inside doc ready block:
$(function(){ // <-------doc ready
$('#email').focus(); // <----use focus event
});
Document ready ensures that DOM is ready and can be used. Either you wrap your js code inside this block or put the script at the bottom of the page. which runs when whole page gets loaded.
If you are using HTML5 then you might look into autofocus attribute:
<input type='text' id='email' autofocus />
focus()perhaps?