why can't I get the value of the data-price attribute?
I want to get the data-price value, make conversions, and add it to the html markup I know how to do it in jquery, but not in js
JS code:
let btn = document.getElementById('btn');
let counter = document.getElementById('counter');
btn.addEventListener("click", function () {
btn.getAttribute('data-price');
counter.innerHTML = btn;
console.log(btn);
});
HTML code:
<div class="card" style="width: 18rem;">
<img src="img/img3.jpg" class="card-img-top" alt="...">
<div class="card-body">
<h5 class="card-title">Card title</h5>
<p class="card-text">Some quick example text to build on the card title and make up the bulk of the card's content.</p>
<div id="price" class="card__price">2499р</div>
<a href="#" id="btn" data-price="2499" class="btn btn-primary">В корзину</a>
</div>
</div>
Console:
<a href="#" id="btn" data-price="2499" class="btn btn-primary">В корзину</a>
const price = btn.getAttribute('data-price');