Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

173
Vistas
Setting focus in contenteditable div in Firefox

hoping you can answer a question. I noticed that the autofocus attribute in a contenteditable div does not work in Firefox. It does work in Chrome and Edge.

<!doctype html>
<html lang="en-US">
<head>
  <title>Focus</title>
  <meta charset="utf-8">
  </style>
  </head>
  <body>
    <div contenteditable autofocus><div>
  </body>
</html>

If I add some javascript before the body close tag:

<script>
window.onload = () => {
// autofocus doesn't work in contenteditable, so add this javascript
document.querySelector("[contenteditable]").focus();
}
</script>

Now I see the focus ring, but FF doesn't actually set focus. There is no cursor/caret and when I type, nothing appears in the div.

So I add some more javascript to put an empty string in the div textcontent. The whole thing now looks like this:

<!doctype html>
<html lang="en-US">
<head>
  <title>Test<title>
  <meta charset="utf-8">
  </style>
  </head>
  <body>
    <div contenteditable autofocus><div>
    <script>
      window.onload = () => {
        // autofocus doesn't work in contenteditable, so add this javascript
        document.querySelector("[contenteditable]").focus();
        // firefox doesn't actually set focus without putting something in text content?
        document.querySelector("[contenteditable]").textContent = "";
      }
    </script>
  </body>
</html>

Finally it works.

I'm on FF 95.0.1 in Ubuntu but I saw the same behavior in Windows 10. What gives? Am I missing something?

about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda