javascript : how to distinguish between selected element list and form
Here is the scripts: http://jsbin.com/itusut/6/edit
Hi, i have function:
function on(t, e, f) {
if ( e.length ) {
var l = e.length,
n = 0;
for ( ; n < l; n++ ) {
e[n].addEventListener(t, f, false)
}
} else {
e.addEventListener(t, f, false);
}
}
if we do var handle = document.getElementsByClassName('some-class'); then
handle is a node list.
if we do var handle = document.getElementById('an-id'); then handle is a
single node.
The problem is, when i choose <form id="login-form"> it returns array not
single element.
So, my on function is fail. The function use elm.length filter. Everything
is ok, except for <form> . How to fix this? i know elm.length not work
properly on single node <form> element.
Would you help? Thank you very much
No comments:
Post a Comment