Quote:
|
Could that mean the elements haven't loaded yet?
|
Yes, as has been mentioned a couple of times

. You need to run the code that attaches events (using getElementById) after the page has loaded. You could either move it into code that runs on the window-load event or move all your JS to the bottom of the page, just before the closing BODY tag.
You might use a slightly extended version of your dollar-function:
Code:
var $ = function () {
// Example: var els = $('obj1name',obj2,'obj2name');
// Saves having to write 'document.getElementById' repeatedly,
// but could also be useful for grouping elements.
var elements = {}, argLen, i, element;
for (i = 0, argLen = arguments.length; i < argLen; i++) {
element = arguments[i];
if (typeof element === 'string')
element = document.getElementById(element);
if (argLen === 1)
return element;
elements.push(element);
}
return elements;
};
It is no where near as comprehensive as jQuery's but slightly more flexible than your current version. You can supply it a string (an elements' id), an element-object reference, or several of these separated by commas.