Looking for a way to extract an attribute from a div and use it to create a link within the same div with the attribute included in the src.
Currently, my code only picks up the first attribute, resulting in all links being the same.
I am still a beginner in JS, so please excuse me if the solution is obvious
var srpVin = document.querySelectorAll('span[data-cg-vin]')[0].getAttribute("data-cg-vin");
var srpVsaBtn = document.getElementsByClassName('carBannerWrapper');
for (var i = 0; i < srpVsaBtn.length; i++) {
srpVsaBtn[i].innerHTML += '<a href="https://myurl.com/?vin='+srpVin+'&dealer_id=28987" target=_deal>Click here - '+srpVin+'</a>';
}
<div class="carBannerWrapper"><div><span data-cg-vin="1FMCU9G66MUA11123" data-cg-price="34399"></span></div></div>
<div class="carBannerWrapper"><div><span data-cg-vin="MAJ3S2GE7LC386456" data-cg-price="34399"></span></div></div>
<div class="carBannerWrapper"><div><span data-cg-vin="11FMCU9H67LUC59789" data-cg-price="34399"></span></div></div>