Questions tagged [onfocus]

onfocus is an event in HTML and JavaScript that triggers when the referenced object gains focus. This tag should be used only in conjunction with the primary language tag, and only for questions where the onfocus event is central to the issue(s) being addressed.

The focus event triggers when a visitor focuses on an element.

Not all elements are focusable by default. For example, INPUT and all types or form fields support this event, A supports it. As a counterexample, DIV doesn't support focus.

The list of elements types which support focusing is slightly different between browsers.

Tutorial

498 questions
3
votes
2 answers

html onfocus tab vs page load

Let's say I have an onFocus event for a text box. That event triggers when the user tabs into that box, as expected. But it also seems like the event triggers when the box is selected, and then the window is covered and then uncovered, by switching…
user617123
  • 463
  • 2
  • 9
  • 26
3
votes
1 answer

focus on an input that is located inside another component in vuejs?

I would like to be able to focus on input field when certain keys are entered. The input I would like to focus on exists inside autocomplete-vue. This is where I call it:
Shinwi
  • 69
  • 1
  • 7
3
votes
0 answers

Keyboard accessible React component that mounts on hover and focus?

In a React application, I have a grid of components. Each renders several
tdc
  • 5,174
  • 12
  • 53
  • 102
3
votes
1 answer

css :focus-visible for custom control

a :focus-visible is always shown for input & textarea, and always shown for button only if the focus switched using tab key. The question is: how about a custom control made of
....
. Sometimes a complex custom control is…
Heyyy Marco
  • 633
  • 1
  • 12
  • 22
3
votes
1 answer

Set cursor position when input is onFocus?

I need to set cursor (caret) to 1st position when input is focused: CodeSandbox I guess the following code should be working, but it's not. It works if it's triggered by a button click, though. What am I doing wrong? import React, {…
cbdeveloper
  • 27,898
  • 37
  • 155
  • 336
3
votes
0 answers

How to detect when terminal is in focus using CPython 3.9?

How is it possible to detect when a terminal (CPython 3.9) is in focus ? Cant find any solution for that. In a Python script, I have a global keyboard hook that takes every keyboard-input, where I need it to ignore input when terminal is off…
RePsEj
  • 49
  • 7
3
votes
3 answers

Add class to group specific div on focus with jQuery

In the following code, I'm trying to make it so that when an input is selected (focused), that the formhead div in the associated fieldset changes its background color, and on blur it changes back. I would like to do this by adding a class to that…
hisnameisjimmy
  • 1,508
  • 2
  • 17
  • 24
3
votes
1 answer

How to make :hover appearance remain after click/focus in search bar

I've got a search bar made of three div-containers (magnifying glass icon, input box, arrow icon) within a bigger div. Currently I can hover over the search bar to give it a box-shadow but I want the box-shadow to remain when I click in the text…
Mr.Lupine
  • 77
  • 8
3
votes
1 answer

ROUTERLINK does not support Focus event

This is a snippet of my code from a Vue.js application
  • CompanyDroneFromSector7G
    • 4,291
    • 13
    • 54
    • 97
  • 3
    votes
    2 answers

    How to change onfocus attribute with jquery according to tabindex?

    I have a list of elements in my page which are ordered with tabindex. What I am looking for is how can I emulate that the tab key was pressed so the focus to move on the next element? I am planning to change focus on my elements in a specific time…
    topless
    • 8,069
    • 11
    • 57
    • 86
    3
    votes
    4 answers

    What is wrong with my code for assigning onfocus event to the element?

    I have a following code which I tried to assign onfocus event to the element, so that whenever the element gets focused, call alert. However, alert only appears when the page loaded, and never after that.
    user605660
    • 199
    • 2
    • 2
    • 7
    3
    votes
    3 answers

    React ES6 const - clear input defaultValue on focus

    I am trying to clear the defaultValue of an input on focus and having trouble doing it either inline or in an external function. Thoughts on the best way to do this? If I use value instead of defaultValue it's the same issue. const SomeComponent =…
    Kirk Ross
    • 6,413
    • 13
    • 61
    • 104
    3
    votes
    1 answer

    RecyclerView onFocus event

    I am using a RecyclerView with a LinearLayoutManager to populate an ArrayList of objects. What I need is how to implement the onFocus event when I change the focus from item to item? onClick event works fine, but the onFocus event has no…
    erimeri
    • 181
    • 1
    • 3
    • 17
    3
    votes
    2 answers

    Avoid loosing focus in children

    Feel free to edit the question title if you find something better. I am writing a little plugin for my website, var main = document.getElementById("main"), fakeInput = document.getElementById("fakeInput"), zone =…
    Apolo
    • 3,844
    • 1
    • 21
    • 51
    3
    votes
    0 answers

    Why don't simulated mouse clicks trigger focus event / text cursor?

    I am attempting to redirect a click event from some element that is on screen to a text input that is off screen. Clicking on the element that is on screen triggers a handler that simulates the same event on the off-screen element. When a user…
    Huckle
    • 1,810
    • 3
    • 26
    • 40