0

I would like to know, via javascript, which give a form element has the focus(), to be able to switch to a variable that holds the name of the currently active.

But without using frameworks like jQuery.

And without the use onfocus event within each component of the form.

Is that possible?

M.

Andrei
  • 3,086
  • 2
  • 19
  • 24
Marco Grazia
  • 57
  • 1
  • 4

2 Answers2

1

You could get it by:

document.activeElement
xdazz
  • 158,678
  • 38
  • 247
  • 274
0

try this code,

  document.formname.activeElement

As seen in this answer.

Community
  • 1
  • 1
KarthikManoharan
  • 805
  • 5
  • 12