I have a line <div class="price-box price-final_price" data-role="priceBox" data-product-id="176"> in a large html file.
I need to store the value of product-id inside a variable, so that I can access it globally.
I'm tring to do it with
var var_productid = document.querySelectorAll('div[data-role="priceBox"]')[0].data-product-id;
But it's not working. What am I doing wrong?
.data-product-idis invalid,-is the minus operator for js engine. Since you are using data-attribute, you can access it throughelement.dataset.productId