common-close-0
BYDFi
Trade wherever you are!

How can I add a line in HTML for displaying cryptocurrency prices?

avatarMalik L Mr PandaDec 18, 2021 · 3 years ago1 answers

I want to add a line of code in my HTML file to display real-time cryptocurrency prices. How can I do that?

How can I add a line in HTML for displaying cryptocurrency prices?

1 answers

  • avatarDec 18, 2021 · 3 years ago
    Sure thing! To display cryptocurrency prices in HTML, you can use JavaScript to fetch the prices from a cryptocurrency API and then update the HTML element with the fetched data. Here's an example: ```html <!DOCTYPE html> <html> <head> <script> function fetchPrices() { fetch('https://api.example.com/prices') .then(response => response.json()) .then(data => { document.getElementById('price').textContent = data.price; }); } setInterval(fetchPrices, 5000); // update every 5 seconds </script> </head> <body> <h1 id="price"></h1> </body> </html> ``` This code fetches the price data from the API every 5 seconds and updates the `h1` element with the id `price` with the fetched data. You can customize the API endpoint and the HTML element as per your requirements. If you have any more questions, feel free to ask!