javascript - innerHTML' of null for the time and class when time changes -


i keep on getting uncaught typeerror: cannot set property 'innerhtml' of null on time tells u day, hour, minute. "timediv2.innerhtml = 'it\'s ' + today + ' ' + hour + ':' + minutes + suffix + '
';" 1 being error or when closing time.it changes error or stays @ same line. writing correct?

var imgarray = new array();    imgarray[0] = new image();  imgarray[0].src = 'http://www.weebly.com/editor/uploads/1/1/3/4/11341626/custom_themes/599346900698327146/files/gifs/openlightoff.png';    imgarray[1] = new image();  imgarray[1].src = 'http://www.weebly.com/editor/uploads/1/1/3/4/11341626/custom_themes/599346900698327146/files/gifs/openlighton.gif';          var = new date();  var weekday = new array(7);  weekday[0] = "sunday";  weekday[1] = "monday";  weekday[2] = "tuesday";  weekday[3] = "wednesday";  weekday[4] = "thursday";  weekday[5] = "friday";  weekday[6] = "saturday";    var today = weekday[now.getday()];    var dayofweek = now.getday();    var hour = now.gethours();    var minutes = now.getminutes();          var suffix = hour >= 12 ? "pm" : "am";  var checktime2 = function() {          var timediv2 = document.getelementbyid('timediv2');          //add or pm          // add 0 1 digit minutes    if (minutes < 10) {      minutes = "0" + minutes    };      if ((dayofweek == 1 || dayofweek == 2 || dayofweek == 3 || dayofweek == 4 || dayofweek == 0 ) && hour >= 6 && hour <= 21) {      hour = ((hour + 11) % 12 + 1); //i.e. show 1:15 instead of 13:15    	timediv2.innerhtml = 'it\'s ' + today + ' ' + hour + ':' + minutes + suffix + '<br><center><img style="width:100%;top:0px;border-radius:10px;" src= '+imgarray[1].src+'></center>';      timediv2.classname = 'open';    }         else if ((dayofweek == 5 || dayofweek == 6) && hour >= 6 && hour <= 22){      hour = ((hour + 11) % 12 + 1);  	timediv2.innerhtml = 'it\'s ' + today + ' ' + hour + ':' + minutes + suffix + '<br><center><img style="width:100%;top:0px;border-radius:10px;" src= '+imgarray[1].src+'></center>';      timediv2.classname = 'open';    }         else {      if (hour == 0 || hour > 5) {        hour = ((hour + 11) % 12 + 1); //i.e. show 1:15 instead of 13:15      }         timediv2.innerhtml = 'it\'s ' + today + ' ' + hour + ':' + minutes + suffix + '<br><center><img style="width:100%;top:0px;border-radius:10px;" src= '+imgarray[0].src+' ></center>';       timediv2.classname = 'closed';    }  };    var currentday = weekday[now.getday()];  var currentdayid = "." + currentday; //gets todays weekday , turns id  $(currentdayid).toggleclass("today"); //hightlights today in view hours modal popup      checktime2();
 [id ^="timediv"]   {        width:100%;    background: transparent;    margin: 0 auto;      border-radius: 3px;     /* -webkit-box-shadow: 0 8px 16px -8px #adadad;    -moz-box-shadow: 0 8px 16px -8px #adadad;    box-shadow: 0 8px 16px -8px #adadad;*/    display:block;      background-color: rgb(0,0,0); /* fallback color */      background-color: rgba(0,0,0,0.5); /* black w/ opacity */  }    .day {    display: inline-block;    float: left;  }    .time {    display: inline-block;    float: right  }    .today {    color: rgb(200, 85, 39);    font-weight: 600;  }    .closed {      color: rgba(231, 76, 60, 0.85);    }    .open {    position:relative;    color: #27ae60;    }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.2.3/jquery.min.js"></script>    <div id="timediv2"></div>

since timediv2 element part of dom, best chance run javascript code before html being loaded.

you can fix calling checktime2() function once page has loaded:

$(function() {     checktime2(); }); 

Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

performance - Why is XCHG reg, reg a 3 micro-op instruction on modern Intel architectures? -

jquery - Responsive Navbar with Sub Navbar -