I have an API that show me real time ETH price. I want to put this price into data-price <option value="ETH" data-price="**HERE**">
Here is Webhook that takes price
let btc = new WebSocket('wss://stream.binance.com:9443/ws/btcusdt@trade')
let BTCPrice = document.getElementById('BTC-price')
btc.onmessage = (event) => {
let stockObject = JSON.parse(event.data);
BTCPrice.innerText = parseFloat(stockObject.p).toFixed(2);
}
And here in "data-price" I want to put it
<select name="pSelect" id="pSelect" data-plan="1" tabindex="-98">
<option data-icon="ico-Ethereum" value="ETH" data-price="1400.08" data-valute="ETH" data-precision="8" valute="Ethereum">
...
...
</select>
The "data-price=1400.08" I wrote manually but I want to make it automatically, either live value, either when page refreshes
CodePudding user response:
I found how to make it, you just need to write
document.querySelector("#ID_OF_SELECT option[value=VALUE_FROM_OPTION]").setAttribute("data-price", thePrice;