How to getElementsByClassname from another url?

606 views Asked by At

I'm trying to make a web page with some data from another url.

Link I want data from

I want to get the 5 cheapest item prices to my page. Is it possible to use getElementsByClassname to get the prices? I know that the class of the prices is item-amount.

1

There are 1 answers

3
relentless-coder On

I am assuming that you are using GET request to obtain the data.

If so, then the data must be in JSON format. From there on it is easy. You can't use getElementsByClassName because it doesn't understand that language.

Let's assume you have the JSON data as.

[{
  "name": "belt",
  "price": "$2"
}, {
  "name": "shirt",
 "price": "$10"
}]

In this case, you can use the data simply by accessing the price property.