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

166
Vistas
How can I cancel changes applied to an html element when hovering ( or clicking) on that element, after the relevant code is runned and finished?

I am trying to understand the DOM manipulation through JS, As an example, I used a form. Let's suppose I hover over an input field or even click, the background of the form will go dark( just an example). How can I cancel this change ( so that the background ocne again becomes light-blue), once I hover out the input field or click outside the form?

here is the code I am using for this : https://codepen.io/abdou-web-dev/pen/QWMxwdB

document.querySelectorAll("input").forEach((inputt) => {
    inputt.addEventListener('click', funct3);

    function funct3(e2) {
        myform.style.backgroundColor = "black"
    };
});

any help will be appreciated, thanks !

about 4 years ago · Juan Pablo Isaza
3 Respuestas
Responde la pregunta

0

You can use the 'blur' event listener for this.

document.querySelectorAll("input").forEach((inputt) => {
    inputt.addEventListener('blur', funct3);

    function funct3(e2) {
        myform.style.backgroundColor = "lightblue";
    };
});

The blur event occurs when a DOM element loses its focus.

You can even implement this with pure css.

Use the :hover pseudo-class or :focus pseudo-class and you can write your color changes there

about 4 years ago · Juan Pablo Isaza Denunciar

0

Thanks to scandav, I found the solution , which is :

document.querySelectorAll("input").forEach((inputt) => {
    inputt.addEventListener('mouseleave', funct3);
    function funct3(e2) {
        myform.style.backgroundColor = "rgba(135, 206, 250, 0.281)"
    };
});
about 4 years ago · Juan Pablo Isaza Denunciar

0

Another way to implement this (if you're going for hover effects) would be to use mouseenter and mouseleave events.

Like this...

document.querySelectorAll("input").forEach((inputt) => {
    inputt.addEventListener('mouseenter', funct3);
    inputt.addEventListener('mouseleave', funct4);

    function funct3(e2) {
        myform.style.backgroundColor = "black"
    };
    function funct4(e2) {
        myform.style.backgroundColor = "lightblue"
    };
});
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