How to recover an item deleted using jQuery?

if an item is deleted using

$('.notification').remove();

How do we create it.

+3
source share
4 answers

You cannot return this particular instance. Using $.remove()removes it from the DOM. You can create a clone of this, move it around the DOM, hide it, etc., though. Depending on what your project requires, you are likely to have many other options.

If you are not too interested in this particular instance, you can create a new one. Suppose this was a div with a statement:

$("<div />").addClass("notification").text("I exist!").appendTo("body");

If you want to keep a copy of this element around, you can $.clone()delete it and the original:

var clone = $(".notification").clone(); // making zeh' clones!
$(".notification").remove();            // original is gone
$("body").append(clone);                // appears to have returned
+9

jQuery 1.4 .detach(). "" DOM , .

+11

detach() remove() , remove . - , DOM

noti = $('.notification').remove();
$('body').append( noti ); // later
+4

.replaceWith(), , . , .

var backUpReplaced = $('.notification').replaceWith('');    

var,

0

Source: https://habr.com/ru/post/1733642/


All Articles