javascript - Error trying to change innerHTML — Cannot set property 'innerHTML' of null -


i trying change innerhtml of div based on number populated javascript function. unfortunately getting error , unsure why.

pseudocode

if number > 2 change innerhtml seconds otherwise change second.

i had around , found related function being triggered before dom. did changes still no success. doing wrong? how can make trigger function after dom being rendered? isn't window.onload doing work?

thank in advance

js

$(document).ready(function() {   window.onload = function() {     // month,day,year,hour,minute,second     uptime('may,05,2006,00:00:00');   };    function uptime(countto) {       var = new date();       countto = new date(countto);       var difference = (now - countto);        var years = math.floor(difference / (60 * 60 * 1000 * 24) / 365);       var days = math.floor(difference / (60 * 60 * 1000 * 24) * 1);       var hours = math.floor((difference % (60 * 60 * 1000 * 24)) / (60 * 60 * 1000) * 1);       var mins = math.floor(((difference % (60 * 60 * 1000 * 24)) % (60 * 60 * 1000)) / (60 * 1000) * 1);       var secs = math.floor((((difference % (60 * 60 * 1000 * 24)) % (60 * 60 * 1000)) % (60 * 1000)) / 1000 * 1);        document.getelementbyid('years').firstchild.nodevalue = years;       document.getelementbyid('days').firstchild.nodevalue = days;       document.getelementbyid('hours').firstchild.nodevalue = hours;       document.getelementbyid('minutes').firstchild.nodevalue = mins;       document.getelementbyid('seconds').firstchild.nodevalue = secs;        if (secs > 2) {         console.log('over');         document.getelementbyid('.seconds').innerhtml = "seconds";       } else {         console.log('lower');         document.getelementbyid('.seconds').innerhtml = "second";       }        cleartimeout(uptime.to);       uptime.to = settimeout(function() {           uptime(countto);       }, 1000);   } }); 

get element class: document.getelementsbyclassname('seconds') , id document.getelementbyid('seconds')

but jquery, id $('#seconds') , class $('.seconds')


Comments

Popular posts from this blog

service - Android MediaPlayer calls onCompletion before it already finished -

javascript - Training Neural Network to play flappy bird with genetic algorithm - Why can't it learn? -

javascript - Create a stacked percentage column -