Question

My html has several DIV:

<div id="div1"></div>
<div id="div2"></div>

In my Jquery script I am trying to use replaceWith to replace a particular <div> with

<div>I'm new!</div>

However, I'm not able to target a particular Div. I only seem able to replace all <div> with this new div. I can also add a class or anything else to the div if necessary.

Was it helpful?

Solution

What about

$("#div1").replaceWith("<div>I'm new!</div>");

Have you tried it?

The jQuery documentation for replaceWith explains this quite well.

OTHER TIPS

http://api.jquery.com/id-selector/

$("#div1") should grab the specific ID.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top