B0B0
B0B0

Reputation: 13

Changing Font Sizes In A Table Inside A Div

I have this code:

   <script>
if ((screen.width<=700) && (screen.height<=1200))
{
  document.getElementById("Table").style.fontSize = "64px";
}
else
{
  document.getElementById("Table").style.fontSize = "40px";
}
</script>
<body>
  <div id="Table">
  <center>
    <table border="0" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF" height="60"         width="100%">
      <tr>
        <td align="center" valign="center"><a href="https://www.google.com">Hello</a>    </td>
      </tr>
    </table>
  </center>
  </div>
</body>`

I want to change the font size of everything inside the div If that isn't possible then please tell me how to change the font size of only the tables.

Thanks

Upvotes: 0

Views: 1439

Answers (1)

Jukka K. Korpela
Jukka K. Korpela

Reputation: 201618

Move the script element to the end of the body element.

What happens now is (as you can see by looking at the console in Developer Tools of your browser, press F12 to enter them) is that document.getElementById("Table") yields null. The reason is that the browser executes the JavaScript code before it has parsed the HTML code that comes after the script element, so there is no element with id value of Table.

There are many ways to prevent JavaScript code from running before it can access all the data it needs. In this case, moving the script element is simplest.

Upvotes: 1

Related Questions