0

I have a table row of a calendar that I need to go on and off according to the month.

HTML:

<tr id="bottomrow" class="week" valign="top" style="display:none;">
        <td class="day" id="d36">
            <div class="daynumb" id="x36"></div>
        </td>
        <td class="day" id="d37">
            <div class="daynumb" id="x37"></div>
        </td>
        <td class="day" id="d38">
            <div class="daynumb" id="x38"></div>
        </td>
        <td class="day" id="d39">
            <div class="daynumb" id="x39"></div>
        </td>
        <td class="day" id="d40">
            <div class="daynumb" id="x40"></div>
        </td>
        <td class="day" id="d41">
            <div class="daynumb" id="x41"></div>
        </td>
        <td class="day" id="d42">
            <div class="daynumb" id="x42"></div>
        </td>
    </tr>

I tried using document.getElementByID('bottomrow').style.display = "none"; but it doesn't seem to be working...

JavaScript:

function february() {

document.getElementById('bottomrow').style.display = "none";

var numbdays = 28,
    offset = 5;

for (var date = 1; date <= numbdays; date++) {
    document.getElementById("x" + (date + offset)).innerHTML = date;
}
}

When the page loads, the row is still visible. What am I doing wrong?

Ryan Fitzgerald
  • 305
  • 4
  • 8
  • 19

3 Answers3

1

You're doing it correctly except getElementByID is not a function. It has to be getElementById. Notice the lowercase d:

document.getElementById("bottomrow").style.display = "none";
Alex W
  • 33,401
  • 9
  • 92
  • 97
0

Is the function running before the DOM is ready? It can't operate on elements that don't exist yet.

window.onload = function ()
{
  ...
} 
isherwood
  • 46,000
  • 15
  • 100
  • 132
0

You should be using the proper handling of the ready event for the page because the DOM elements haven't loaded on the page yet. jQuery abstracts this but take a look at this post on how to do it without jQuery or another library. You need to be sure to handle the differences in browsers which the following guide will do.

$(document).ready equivalent without jQuery

Community
  • 1
  • 1
Paul Mendoza
  • 5,494
  • 9
  • 47
  • 80