Using javascript to read value from itemprop
Is it possible to read the price using javascript
<span id="product_price_00873">
<span itemprop="price">178.00</span>
</span>
I just want to pay 178.00. I can only use javascript.
Any suggestions would be appreciated.
+3
jbcedge
source
to share
2 answers
var els = document.getElementsByTagName('span'), i = 0, price;
for(i; i < els.length; i++) {
prop = els[i].getAttribute('itemprop');
if(prop) {
price = els[i].innerHTML;
break;
}
}
http://jsbin.com/atimux/edit#javascript,html,live
+7
xandercoded
source
to share
If you have a product item in product
, and you are using a modern browser, this should work:
var price = product.querySelector('[itemprop=price]').textContent;
+8
icktoofay
source
to share