Unexpected token (, when trying to access a table through DOM. I’m trying to show the calendar if it is a certain month of the year, but JS it’s identifying my table elements. There are two possible errors:
- Studio Code: Identifier expected. ts(1003)
- Browser console: Uncaught SyntaxError: Unexpected token ‘(‘
window.onload = getDate();
function getDate() {
let currentMonth = new Date().getMonth() + 1;
let date7 = new Date(7);
let date8 = new Date(August, 2022);
let date9 = new Date(September, 2022);
let date10 = 10;
let date11 = 11;
let date12 = 12;
if (currentMonth == date7) {
document.getElementById.("july_22").style.display="table";
}
else if (currentMonth == date8) {
document.getElementById.("august_22").style.display="table";
}
else if (currentMonth == date9) {
document.getElementById.("september_22").style.display="table";
}
else if (currentMonth == date10) {
document.getElementById.("october_22").style.display="table";
}
else if (currentMonth == date11) {
document.getElementById.("november_22").style.display="table";
}
else if (currentMonth == date12) {
document.getElementById.("december_22").style.display="table";
}
}
<table id="july_22" cols="4" rows="33" cellspacing="20px">
<caption>July</caption>
<thead>
<tr>
<th>Mon</th>
<th>Tue</th>
<th>Wed</th>
<th>Thu</th>
<th>Fri</th>
<th>Sat</th>
<th>Sun</th>
</tr>
</thead>
<tbody>
<tr>
<td class="day"></td>
<td class="day"></td>
<td class="day"></td>
<td class="day"></td>
<td class="day"></td>
<td class="day">1</td>
<td class="day">2</td>
</tr>
<tr>
<td class="day">3</td>
<td class="day">4</td>
<td class="day">5</td>
<td class="day">6</td>
<td class="day">7</td>
<td class="day">8</td>
<td class="day">9<br><p class="message">Fasting Day</p></td>
</tr>
<tr>
<td class="day">10</td>
<td class="day">11</td>
<td class="day">12</td>
<td class="day">13<br><p class="message">Fasting Day</p></td>
<td class="day">14</td>
<td class="day">15</td>
<td class="day">16</td>
</tr>
<tr>
<td class="day">17</td>
<td class="day">18</td>
<td class="day">19</td>
<td class="day">20</td>
<td class="day">21</td>
<td class="day">22<br><p class="message">Ritual</p></td>
<td class="day">23<br><p class="message">Fasting Day</p></td>
</tr>
<tr>
<td class="day">24</td>
<td class="day">25</td>
<td class="day">26</td>
<td class="day">27</td>
<td class="day">28<br><p class="message">Fasting Day</p></td>
<td class="day">29</td>
<td class="day">30</td>
</tr>
</tbody>
</table>
>Solution :
Ypu have a dot after document.getElementById. You need to remove it like
document.getElementById("july_22").style.display = "table";