var list = document.querySelectorAll(".list a");
for(var b = 0; b < list.length; b++) {
var _list2 = document.querySelectorAll(".list2 a");
for(var a = 0; a < _list2.length; a++) {
list[b].href = _list2[a].href;
}
}
<div class="list">
<ul>
<li><a href="#"></a></li>
<li><a href="#"></a></li>
<li><a href="#"></a></li>
<li><a href="#"></a></li>
<li><a href="#"></a></li>
</ul>
</div>
<div class="list2">
<ul>
<li><a href="https://www.sample_a.com"></a></li>
<li><a href="https://www.sample_b.com"></a></li>
<li><a href="https://www.sample_c.com"></a></li>
<li><a href="https://www.sample_d.com"></a></li>
<li><a href="https://www.sample_e.com"></a></li>
</ul>
</div>
<h2>Expected Result</h2>
<div class="list">
<ul>
<li><a href="https://www.sample_a.com"></a></li>
<li><a href="https://www.sample_b.com"></a></li>
<li><a href="https://www.sample_c.com"></a></li>
<li><a href="https://www.sample_d.com"></a></li>
<li><a href="https://www.sample_e.com"></a></li>
</ul>
</div>
How to replace “.list a empty hyperlinks with .list2 hyperlinks” through loop? I am puzzled with this loop. When I am using this loop, I am getting the last hyperlink for all hyperlinks. How to figure this out?