Randomblue Randomblue - 17 days ago 5
jQuery Question

replaceWith() without deleting the original element

Is there a jQuery function similar to

replaceWith()
to replace an element with a new element, without destroying the original element (simply hiding it).

Answer

you can do :

<button>replace</button>
<div class="toReplace">your first content</div >
<div class="toReplace" style="display: none">your second content</div >

then in js :

$("button").click(function () {
  $("toReplace").toggle();
});
Comments