0

I need a simple solution for replacing a div with a new div, cross-browser compatible using javascript or JQuery. I'll add some code below. Div "myDiv-B" needs to be replaced by a new div:

<div id="myDiv-C">{% include 'snippets/contactpaneel.rain' %}</div>

Here are my divs

<div id="myDiv-A">
<div id="myDiv-B"></div>
</div>
Mihai Alexandru-Ionut
  • 47,092
  • 13
  • 101
  • 128
Eddy
  • 566
  • 2
  • 8
  • 28

1 Answers1

1

You should use .replaceWith() method.

.replaceWith method replace each element in the set of matched elements.

$('#myDiv-B').replaceWith('<div>Hello</div>');
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="myDiv-A">
<div id="myDiv-B"></div>
</div>
Mihai Alexandru-Ionut
  • 47,092
  • 13
  • 101
  • 128