Quantcast
Channel: Active questions tagged html - Stack Overflow
Viewing all articles
Browse latest Browse all 72443

getElementByID return null but console.log works fine [duplicate]

$
0
0

This question already has an answer here:

I am learning HTML/Javascript, and am writing some simple functions. I used console.log to return an element, and it returned fine, however, in the same function, when I try to use getElementById(), then I received an error in the console which says that the value is null. Could you help me understand what is wrong?

function calculateProfict() {
   var consumoW_H = 2960;
   var consumoW_D = 2960 * 24 * 0.001; 
   var prezzoElettricita = 0.22;
   var consumoElettricita_D = consumoW_D * prezzoElettricita;
   var valore_BTC = 12.5;
   var valore_BTC_D = 144 * valore_BTC;
   var hashrateGlobal = 100000000
   var networkHashratePercentage = document.getElementById("networkHashrate").innerHTML/hashrateGlobal;
   var BTC_D = networkHashratePercentage * valore_BTC_D;
   var euroBTC_D = BTC_D * 6471.90;
   var guadagno = euroBTC_D - consumoElettricita_D;
   console.log(guadagno) //Return -15.62
   document.getElementById("guadagno").innerHTML = guadagno; //null is not an object

}

I also tried with .value (I don't know if it's right or not) but I received the same error. My point is why I can use console.log and not document.getElementById? Thanks guys and happy new year


Viewing all articles
Browse latest Browse all 72443

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>