Accesing dataset to get the value (shopify)

Viewed 151

I've been struggling to access a specific value when I console log my variable - essentially I've tried the getAttribute method, .dataset and still am getting undefined. I have posted a picture below. but essentialy im trying to get the value of data-checkout-payment-due.

Screenshot of console

    var children = document.getElementsByClassName('payment-due__price')[1].getAttribute("data-checkout-payment-due-target");
        console.log(children);

and

    var children = document.getElementsByClassName('payment-due__price').dataset["checkoutPaymentDueTarget"];
        console.log(children);
1 Answers

is this the answer of your question?

let dataValue = document.querySelector('.payment-due__price').getAttribute("data-checkout-payment-due-target");

console.log(dataValue);
<div class="payment-due__price" data-checkout-payment-due-target="XYZ"></div>

Related