JSFiddle - React, Tailwind, and code Playground

by Rachit Garg

HTML

<body>

<div class="test" id="test">
 <div class="one">sdas</div >
 <div class="two">adsa</div >
 <div class="three">sad</div >
 <div class="four">sada</div >
</div>
<br /><br /><br />
<div id="DIV2">
</div>

<p>Click the button to change the text of the first list item (index 0).</p>

<button onclick="myFunction()">Try it</button>

<script>

function myFunction() {
    var MyDiv2 = document.getElementById('DIV2');
    var items = document.getElementById("test").children;
    var str = 'str';
    var output = [];
    for (var i = 0; i < items.length; i++) {
        output.push(`${items[i].innerHTML} <br /> ${str} <br />`);
    }
    MyDiv2.innerHTML = output.join("");
}

</script>

</body>