I've been stumped on this bug where I am unable to update the innerHTML of my li classes named "currMonth" and "currYear". They are supposed to get updated by the OnStart()
function. I tried using console.log
and it showed that the values were changing behind the scenes. It would be great if someone can show me what I'm doing wrong. Thanks!
HTML:
<!DOCTYPE html>
<html lang = "en-US">
<head>
<title title = "O(n)Time"></title>
<meta charset="UTF-8">
<script src="../js/script.js"></script>
<link rel="stylesheet" type="text/css" href="../css/styles.css">
</head>
<body>
<div class="month">
<ul>
<li class="prev">❮</li>
<li class="next">❯</li>
<li id="currMonth"></li>
<li id="currYear"><span style="font-size:18px"></span></li>
</ul>
</div>
</body>
<ul class="weekdays">
<li>Sunday</li>
<li>Monday</li>
<li>Tuesday</li>
<li>Wednesday</li>
<li>Thursday</li>
<li>Friday</li>
<li>Saturday</li>
</ul>
<ul class="days">
<li>1</li>
<li>2</li>
<li>3</li>
<li>4</li>
<li>5</li>
<li>6</li>
<li>7</li>
<li>8</li>
<li>9</li>
<li><span class="active">10</span></li>
<li>11</li>
<li>12</li>
<li>13</li>
<li>14</li>
<li>15</li>
<li>16</li>
<li>17</li>
<li>18</li>
<li>19</li>
<li>20</li>
<li>21</li>
<li>22</li>
<li>23</li>
<li>24</li>
<li>25</li>
<li>26</li>
<li>27</li>
<li>29</li>
<li>30</li>
<li>31</li>
</ul>
</html>
CSS:
ul {
list-style-type: none;
}
body{
font-family: Verdana, sans-serif;
}
/* Month header */
.month{
padding: 70px 25px;
width: auto;
background: #1abc9c;
text-align: center;
}
/* Month list */
.month ul {
margin: 0;
padding: 0;
}
.month ul li{
color: white;
font-size: 20px;
text-transform: uppercase;
letter-spacing: 3px;
}
/* Previous button inside month header */
.month .prev {
float: left;
padding-top: 10px;
}
/* Next button */
.month .next {
float: right;
padding-top: 10px;
}
/* Weekdays (Sun-Sat) */
.weekdays {
margin: 0;
padding: 10px 0;
background-color: #ddd;
}
.weekdays li {
display: inline-block;
width: 13.6%;
color: #666;
text-align: center;
}
/* Days (1-31) */
.days {
padding: 10px 0;
background: #eee;
margin: 0;
}
.days li {
list-style-type: none;
display: inline-block;
width: 13.6%;
text-align: center;
margin-bottom: 5px;
font-size: 12px;
color: #777;
}
/* Highlight of the "current" day */
.days li .active {
padding: 5px;
background: #1abc9c;
color: white !important
}
JS:
//Constants
MONTHS = ["January", "February", "March", "April", "May", "June", "July",
"August", "September", "October", "November", "December"];
//Variables
var prevArrow = document.getElementsByClassName('prev');
var nextArrow = document.getElementsByClassName('next');
OnStart(MONTHS);
//Functions
function OnStart(MONTHS){
var d = new Date();
var month = d.getMonth();
var year = d.getFullYear();
document.getElementById('currMonth').innerHTML = MONTHS[month];
document.getElementById('currYear').innerHTML = year;
}