replace elements in jQuery

To replace dom elements in jQuery, API provides it’s own inbuilt function replaceWith() and replaceAll().

We can use them as follows:

// select > replace
$(“h1”).replaceWith(“<div>Hello</div>”);
// this will replace all h1 with div having "hello" inside.

// create > replace selection
$(“<div>Hello</div>”).replaceAll(“h1”);

any?’s. Please let me know.


Anoop kumar sharma

Leave a Comment


NOTE - You can use these HTML tags and attributes:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>