Add again after remove
Solution 1
Remove is not a property, the element is actually gone. To just hide it temporarly use hide() and show(), to detach it an reattach it later use detach().
var elm = $("#elementID").detach();
$(button).on('click', function() {
elm.appendTo('#popupID');
});
Solution 2
Before you remove it (which can't be restored!) clone it.
var cloned = $('.foo').clone();
$('.clone').remove();
I'm not sure you're doing the right thing with the removing but I answered your's question.
You might want to hide and show the element inside of completely remove it from the DOM.
MajAfy
Updated on June 09, 2022Comments
-
MajAfy almost 2 years
I removed an element with
remove()
as I said before in : Removing higher layernow when I click again on my link to open popup, the link cannot work because that layer removed before.
How can I remove the remove property from my element ?
UPDATE:
I use
requireJS
plugin to load a JS file when click on link :$('a#addUser').click(function () { require (['controllers/users/add'],function() { $('#loading').fadeOut('fast'); }); });
In controllers/users/add.js I have that popup, user can close popup, I don't have any problem up to here, the problem is when user click again on link and popup should be show again, but in my code that popup does not open again.
ANSWER: The problem is requreJS, because this plugin allow me to load my javascript just one time,
I should use
$.getScript()
instead of requreJS -
MajAfy almost 12 yearsI don't want clone my element, because when user click on link I want to send the request to server again to receive new code (please read update in my question)
-
gdoron is supporting Monica almost 12 years@MajAfy. I'm afraid there are too much info missing in your question, and the update doesn't help much either. If you could show us a fiddle you would get better answers.