getElementByIdreturns nullif there is no match in the document. (Which leads to an accurate error message).
This means that either you have a typo in your selector, or in html or js, it is executed before your element is included in the dom.
In addition, it getElementByIdreturns a single element, not an array ( Node Listto be precise), so the correct call would be:
document.getElementById('td1').style.color = 'blue';
The third problem:
setInterval(test(),1000);
// /\
// this will immeditately execute the function and
// hands over the *return value* to setInterval
,
setInterval(test,1000);