Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jquery textarea (+field) focus not working

Tags:

jquery

focus

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

like image 325
gvanto Avatar asked Feb 03 '14 04:02

gvanto


People also ask

How can input focus in jQuery?

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.

What does focus() do?

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.

How to set focus on an HTML element?

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.


1 Answers

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.

like image 155
Fabrício Matté Avatar answered Sep 29 '22 09:09

Fabrício Matté