I am working in a crypto currency live price page. I am using Coingekho api for it. It is not working in
$<input type="number" id="bitcoin" value=""/>
but it is woring in <h2 id="bitcoin"></h2>
. I need it in <input type="number" id="bitcoin" value=""/>
. Also I need all decimal value of price like $19755.25725.
var btc = document.getElementById("bitcoin");
var ltc = document.getElementById("litecoin");
var eth = document.getElementById("ethereum");
var liveprice = {
"async": true,
"scroosDomain": true,
"url": "https://api.coingecko.com/api/v3/simple/price?ids=bitcoin%2Clitecoin%2Cethereum&vs_currencies=usd",
"method": "GET",
"headers": {}
}
$.ajax(liveprice).done(function(response) {
btc.innerHTML = response.bitcoin.usd;
ltc.innerHTML = response.litecoin.usd;
eth.innerHTML = response.ethereum.usd;
});
$<input type="number" id="bitcoin" value=""/>
$<h2 id="litecoin"></h2>
$<h2 id="ethereum"></h2>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
2
Answers
<input>
elements don’t haveinnerHTML
, since they’re not containers. You need to setbtc.value
.to change the value of the input tag you have to use
btc.value
instead ofbtc.innerHTML