I'm trying to focus (make caret go to, as if it was clicked) a textarea and/or textfield, according to this: How to focus on a form input text field on page load using jQuery?
I really dont get why its not working. On this page: http://gojobr.com.au/blog/working-as-a-teacher/ This, does NOT work (it doesn't do anything):
$("#author").focus()
Same with this page: http://twoggle.com
$("#BlogRequestForm_name").focus()
I can hide and show elements using this selector, but .focus() does nothing. Zero. Zilch.
Any help would be much appreciated.
Using firefox (but it doesn't work in Chrome either).
Does it work for anyone else (using Firebug's console) ?
thanks gvanto
Using jQuery With jQuery, you can use the . focus() method to trigger the “focus” JavaScript event on an element. This method is a shortcut for . trigger("focus") method.
focus() method sets focus on the specified element, if it can be focused. The focused element is the element that will receive keyboard and similar events by default.
To set focus to an HTML form element, the focus() method of JavaScript can be used. To do so, call this method on an object of the element that is to be focused, as shown in the example. Example 1: The focus() method is set to the input tag when user clicks on Focus button.
Does it work for anyone else (using Firebug's console) ?
It works fine, however executing .focus()
from the console will not steal the focus from the console window. After executing the command, close the console window (which automatically returns the focus to the web page) and the focused element will be the one you expect. Tested with Firebug/DevTools.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With