Reputation: 1547
I know about detach() and the varios methods to insert html. But how do you detach an element, leave a placeholder, and then replace that placeholder with the element later on?
The only solution I can think of is to check for a prev(), then next(), then parent(). Store that placeholder, and then later on use that placeholder to put the element back.
There has to be a simpler way...
Thanks.
Upvotes: 1
Views: 2351
Reputation: 2858
Use good 'ol $(elem).css('visibility', 'hidden');
to hide it while keeping it's place,
and then $(elem).replaceWith(newElem);
to swap it out;
Upvotes: 1
Reputation: 3281
For attaching an element you must use .append() like this
$('form').append("<div id='appended'>Hello World</div>");
For detaching an element you should use .remove() like this
$('#appended').remove();
Upvotes: 0