How can I insert or wrap my second div into a new div container with the same class name? I attempted to do this but it didn't work. Can you help me identify what is missing?
<div class="section" id="section1">
<div id="myDIV"> --> I want to wrap this into a new div
asdasd
</div>
</div>
<div class="section" id="section1">
<div id="myDIV">
cbcvbcvb
</div>
</div>
<script>
//org_html = document.getElementById("section1").innerHTML;
//new_html = "<div class='mydiv-container'>" + org_html + "</div>";
//document.getElementById("section1").innerHTML = new_html;
const parentObject = document.getElementById('section1').innerHTML;
[...parentObject].forEach((parent, i) => {
//const childElement = document.createElement('div');
const childElement = "<div class='slidesInner'>" + parentObject + </div>";
document.getElementById("section1").innerHTML = childElement;
});
</script>
Here is the desired result:
<div class="section" id="section1">
<div class="mydiv-container">
<div id="myDIV">
cbcvbcvb
</div>
</div>
</div>
<div class="section" id="section1">
<div class="mydiv-container"> <-- this is not showing in the second section
<div id="myDIV">
cbcvbcvb
</div>
</div>
</div>