Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

activeElement always returns document.body

When testing the following code in Google Chrome version 36.0.1985.49 on an iPhone 5 running iOS 7.0.6, it always alerts BODY even when focused on the input element, but it should alert INPUT. Would there be any way to get the focused element cross-browser without tracking every focus and blur?

HTML:

<input type="text">

JS:

setInterval(function () {
    alert(document.activeElement.tagName);
}, 5000);


Fiddle

Also, $(':focus') just gives no result for mobile chrome because it probably ignores when document.body is the focused element.

Mobile Safari works exactly as it should.

Non-Duplicates:

  • how to find activeelement in chrome in jquery or javascript (Doesn't even mention mobile chrome)
  • document.activeElement returns body in Chrome and Safari (Again, doesn't mention mobile chrome and the solution doesn't even work)
like image 789
Anonymous Avatar asked May 21 '26 06:05

Anonymous


1 Answers

JSfiddle was blocking the input element on mobile chrome with another element above it, so it was never actually focused. It just looked focused.

like image 176
Anonymous Avatar answered May 23 '26 21:05

Anonymous