Saturday, June 1, 2024
 Popular · Latest · Hot · Upcoming
20
rated 0 times [  24] [ 4]  / answers: 1 / hits: 16298  / 13 Years ago, fri, march 9, 2012, 12:00:00

Is it possible the read the price using the javascript



<span id=product_price_00873>
<span itemprop=price>178.00</span>
</span>


I just want to price 178.00. I can only using javascript.



Any suggestions will be appreciated.


More From » javascript

 Answers
9

Update:


Use Element.querySelector as described in icktoofay's answer, or perform the following:


const els = [...document.getElementsByTagName('span')];
props = els.filter(x => !!x.getAttribute('itemprop'));

// print the first element's price
console.log(props.shift().innerHTML)



Original:


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;
}
}

[#86964] Thursday, March 8, 2012, 13 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
patienceannel

Total Points: 674
Total Questions: 101
Total Answers: 101

Location: Northern Mariana Islands
Member since Fri, Jan 15, 2021
3 Years ago
patienceannel questions
Fri, Mar 11, 22, 00:00, 2 Years ago
Tue, Oct 20, 20, 00:00, 4 Years ago
Wed, Jul 24, 19, 00:00, 5 Years ago
;