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

186
Vistas
When you leave input field, a function is triggered which change input background color

How can I do like, when my cursor leave input field, a function is triggered which change input background color. I was trying to do like this, but did not work well.

<!DOCTYPE html>
<html>
<body>

Enter your name: <input type="text" id="name" onchange="changeColor()">

<script>
function changeColor() {
  const x = document.getElementById("name");
  x.style.background = "red";
}
</script>

</body>
</html>
about 4 years ago · Juan Pablo Isaza
3 Respuestas
Responde la pregunta

0

function changeColor(ev) {
  ev.target.style.backgroundColor = "red";
}
about 4 years ago · Juan Pablo Isaza Denunciar

0

You can use the blur event to target specifically the lose of focus:

Enter your name: <input type="text" id="name">

<script>
const x = document.getElementById("name");

x.onblur = changeColor;

function changeColor() {
  x.style.background = "red";
}
</script>
about 4 years ago · Juan Pablo Isaza Denunciar

0

Try the onmouseleave event listener. onchange usually involved the value of the input field changing.

In CSS you have :focus selector to style based of if the input is focused or not

about 4 years ago · Juan Pablo Isaza Denunciar
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