Clone and insert HTML in all occurrence in pure js please

How do I insert the Australian-Brothers class html before every div with the LongLiveAustralia class?
all occurrence pure js please

It’s like this

<div class="Australian-Brothers">Hello World</div>
<div class="American-Brothers">
<div class="LongLiveAustralia"></div>
<div class="LongLiveAustralia"></div>
<div class="LongLiveAustralia"></div>
<div class="LongLiveAustralia"></div>
</div>
``
have to stay like this:

<div class="American-Brothers">
<div class="Australian-Brothers">Hello World</div><div class="LongLiveAustralia"></div>
<div class="Australian-Brothers">Hello World</div><div class="LongLiveAustralia"></div>
<div class="Australian-Brothers">Hello World</div><div class="LongLiveAustralia"></div>
<div class="Australian-Brothers">Hello World</div><div class="LongLiveAustralia"></div>
</div>
let helpmybrother = document.querySelector('.Australian-Brothers').cloneNode(true);

document.querySelector('.LongLiveAustralia').before(helpmybrother);

you’re going to want a querySelectorAll and a forEach.

Thank you for replying, It might be

Thanks for the answers I solved so:

const selectTest = document.querySelectorAll('.LongLiveAustralia');
selectTest.forEach(function (select) {
    clone = document.querySelector(".Australian-Brothers").cloneNode(true);
 select.before(clone);

});

1 Like