Form elements have the length property (specify the number of fields in the form). The code you use does not accurately determine if this element is a DOM node, so it assumes that the form is a collection of DOM nodes.
If you need to bind elements, you are probably best off passing an array object or an array, so the function always iterates through the collection.
It can be as simple as moving a parameter to an array:
on('click', [formElement], callback);
Updated version on , where only lists are supported: function on(type, elements, callback) { var length, i; length = 0; if (elements && elements.length) { length = elements.length; } for (i = 0; i < length; i += 1) { elements[i].addEventListener(type, callback, false); } }
source share