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

192
Vistas
How to revert css properties in jQuery

In my jQuery function, I am animating a div element, so it moves 200px to right, receives a Moved class and some opacity:

if (!$(".block2").hasClass("Moved2")) {
    $(".block2").animate({
        "left": "+220px"
    }, "slow", function() {
        $.ajax
        ({url: 'play.php',
            data: {"var1": val},
            type: 'get',
            success: function(json) {
                if(!json.error) {$(".block2").removeClass("Moved2").css({left:"0",opacity:"1"});}
        }});
    } ).fadeTo("slow", 0.33).addClass("Moved2");
}

This works fine, but after it finishes, I want to have all properties and css back as they were before animation. But I don't want to reload the page.

As you can see, now I do it this way:

$(".block2").removeClass("Moved2").css({left:"0",opacity:"1"});

It does what I want, but there might be more properties affected in another functions and I don't want to change each element one by one. Is there a kind of UNDO for everything done by that jQuery sequence?

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

0

You can use removeAttr(), in this way, it will remove all inline styles added to class .block2

$(".block2").removeClass("Moved2").removeAttr("style")
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