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


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


source


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


source







All Articles