How to make an element return as it was after an action with jquery

Asked

Viewed 107 times

1

I have a li and by the css I left it as a square and put an image in the background with the css, when my user clicks this image comes out and enters a text and when he re-clicks the image back, I would like to know how I make it so that I read it again as it was in the beginning after this new click. Thank you

  • What kind of action? Position, value, attribute is changed?

1 answer

1


Use the method clone(), creating 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 on Jsfiddle.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.