Questions tagged [focus]

Focus indicates the component of the graphical user interface which is currently selected to receive input.

Focus indicates the component of the graphical user interface which is currently selected to receive input. Text entered at the keyboard or pasted from a clipboard is sent to the component which currently has the focus. Typically, the focus is withdrawn from an element by giving another element the focus.

The concept is similar to a cursor in a text-based environment. However, when considering a graphical interface, there is also a mouse cursor involved. Moving the mouse will typically move the mouse cursor without changing the focus. The focus can usually be changed by clicking on a component that can receive focus with the mouse. Many desktops also allow the focus to be changed with the keyboard. By convention, the tab key is used to move the focus to the next focusable component and shift + tab to the previous one. When graphical interfaces were first introduced, many computers did not have mice, so this alternative was necessary. This feature makes it easier for people that have a hard time using a mouse to use the user interface. In certain circumstances, the arrow keys can also be used to move focus.

7243 questions
3152
votes
54 answers

How to stop EditText from gaining focus when an activity starts in Android?

I have an Activity in Android, with two elements: EditText ListView When my Activity starts, the EditText immediately has the input focus (flashing cursor). I don't want any control to have input focus at startup. I…
Mark
  • 39,551
  • 15
  • 41
  • 47
1750
votes
11 answers

How to remove focus border (outline) around text/input boxes? (Chrome)

Can anyone explain how to remove the orange or blue border (outline) around text/input boxes? I think it only happens on Chrome to show that the input box is active. Here's the input CSS I'm using: input { background-color: transparent; …
Joey Morani
  • 25,431
  • 32
  • 84
  • 131
722
votes
25 answers

Is there a way to detect if a browser window is not currently active?

I have JavaScript that is doing activity periodically. When the user is not looking at the site (i.e., the window or tab does not have focus), it'd be nice to not run. Is there a way to do this using JavaScript? My reference point: Gmail Chat plays…
Luke Francl
  • 31,028
  • 18
  • 69
  • 91
542
votes
48 answers

How to show soft-keyboard when edittext is focused

I want to automatically show the soft-keyboard when an EditText is focused (if the device does not have a physical keyboard) and I have two problems: When my Activity is displayed, my EditText is focused but the keyboard is not displayed, I need to…
Ludovic Landry
  • 11,606
  • 10
  • 48
  • 80
429
votes
18 answers

Android: Force EditText to remove focus?

I would like to be able to remove the focus from the EditText. For example if the Keyboard appears, and the user hides it with the back button, I would like the focus and the cursor to disappear. How can it be done?
Alex1987
  • 9,397
  • 14
  • 70
  • 92
427
votes
8 answers

How to reset / remove chrome's input highlighting / focus border?

I have seen that chrome puts a thicker border on :focus but it kind of looks off in my case where I've used border-radius also. Is there anyway to remove that?
Jiew Meng
  • 84,767
  • 185
  • 495
  • 805
416
votes
13 answers

How can I set focus on an element in an HTML form using JavaScript?

I have a web form with a text box in it. How do I go about setting focus to the text box by default? Something like this: so can anybody help me with it? I don't know how to set focus to the text box with…
tenstar
  • 9,816
  • 9
  • 24
  • 45
321
votes
8 answers

Is it possible to focus on a

Is it possible to focus on a
using JavaScript focus() function? I have a
tag
You have 3 tries left
I am trying to focus on the above
using : document.getElementById('tries').focus(); But it doesn't work.…
OM The Eternity
  • 15,694
  • 44
  • 120
  • 182
320
votes
6 answers

Which HTML elements can receive focus?

I'm looking for a definitive list of HTML elements which are allowed to take focus, i.e. which elements will be put into focus when focus() is called on them? I'm writing a jQuery extension which works on elements that can be brought into focus. I…
Paul Turner
  • 38,949
  • 15
  • 102
  • 166
296
votes
12 answers

How to focus on a form input text field on page load using jQuery?

This is probably very simple, but could somebody tell me how to get the cursor blinking on a text box on page load?
chris
  • 20,791
  • 29
  • 77
  • 90
288
votes
18 answers

Prevent the keyboard from displaying on activity start

I have an activity with an Edit Text input. When the activity is initialized, the Android keyboard is shown. How can the keyboard remain hidden until the user focuses the input?
Fcoder
  • 9,066
  • 17
  • 63
  • 100
262
votes
5 answers

jQuery lose focus event

I'm trying to show up a container if a input field gets the focus and - that's the actual problem - hide the container if focus is lost. Is there an opposite event for jQuery's focus? Some example code:
xijo
  • 4,366
  • 4
  • 23
  • 30
233
votes
21 answers

How can I set the focus (and display the keyboard) on my EditText programmatically

I have a layout which contains some views like this: How can I set the focus (display the keyboard) on my EditText programmatically? I've tried…
Houcine
  • 24,001
  • 13
  • 56
  • 83
232
votes
33 answers

In React ES6, why does the input field lose focus after typing a character?

In my component below, the input field loses focus after typing a character. While using Chrome's Inspector, it looks like the whole form is being re-rendered instead of just the value attribute of the input field when typing. I get no errors from…
spunge
  • 2,827
  • 3
  • 14
  • 12
231
votes
9 answers

How do you clear the focus in javascript?

I know this shouldn't be that hard, but I couldn't find the answer on Google. I want to execute a piece of javascript that will clear the focus from whatever element it is on without knowing ahead of time which element the focus is on. It has to…
Andres
  • 5,012
  • 3
  • 24
  • 36
1
2 3
99 100