Q:

TypeError: document.getElementsByTagName(...).className is undefined

I keep getting 

TypeError: document.getElementsByTagName(...).className is undefined

What's up with that, I don't really get it.
function test(){
    if ( document.getElementsByTagName("body").className.match(/(?:^|\s)test(?!\S)/) ){
        document.getElementsByTagName("body").className += " test";
        alert("test");
    }
}

document.onload = test();

A:

Note that it's getElementsByTagName, not getElementByTagName -- it's plural. It returns a list of elements.
To add a class to the first element in that list:
if ( document.getElementsByTagName("body")[0].className.match(/(?:^|\s)test(?!\S)/) ){
    document.getElementsByTagName("body")[0].className += " test";
    alert("test");
}

