As you can see in below snippet the code of class="CardData"
is copied to class="optionData"
.
But I want to copy only the li
tag but here <button> & <a>
tags are also copied.
I tried to use getElementsByTagName
but it is displaying data without bullets and had to specify [0],[1],[2],.....
to display all . As there can be any number of details it is cumbersome to do that .
Is there any way to copy data from class="CardData"
to class="optionData"
with only li
tag with a single JS
Let me know if you need clarification
function details(saad) {
var reed2 = saad.parentElement.getElementsByClassName("CardData")[0].innerHTML;
document.getElementsByClassName("optionData")[0].innerHTML = reed2;
}
document.querySelectorAll(".CardBtn").forEach(details);
<div>
<ul class="CardData">
<li>Windows 11</li>
<li> 8GB Ram</li>
<li>1TB SSD</li>
<li>Intel Core i7 (11th Gen)</li>
<a>Not in the stock</a>
<li>NVIDIA GeForce GTX 1050</li>
<li>15.6 inch Full HD Display</li>
<li> Dolby Audio</li>
<li>1 Year Onsite Warranty</li>
<button class="MoreLess">+Show More</button><br>
</ul>
<button class="CardBtn" onclick="details(this)">Buy</button>
<hr>Data Box:<br><br>
<span class="optionData"> </span>
<hr>
</div>