How to make an element go back as it was after an action with jquery [closed]

1

I have a li and by css I left it as a square and I put an image in the background with the css, when my user clicks this image leaves and enters a text and when he clicks the image again, I would like to know how I make it to return to be as it was at the beginning after this new click. Thanks

    
asked by anonymous 03.07.2015 / 16:27

1 answer

1

Use the clone () method, which creates a copy of the element.

var elementoOriginal = $("#box").clone();

$("#btn-remover").click(function() {
    $("#box").css('background','yellow');
});


$("#btn-restaurar").click(function() {
   $("#box").remove();
   $("body").prepend(elementoOriginal);
});

See example working in JSFiddle .

    
03.07.2015 / 16:57