Possible Duplicate:
Javascript isDOM — How do you check if a Javascript Object is a DOM Object?
I have the following simple function:
function do_smth(el){
if(typeof el != 'object'){
el = this
}
var val = $.trim(el.value)
/**** some code here ****/
}
Sometimes it is binded to an element as an event
1)
element.onclick = do_smth
and sometimes it is used the following way
do_smth(element)
both ways this should work good...
The problem is that I get the el
as Event
object in the first case, even if there are no arguments passed.
So typeof el != 'object'
does not work as expected.
How can I distinguish DOM element or Event?
function do_smth(el){
el = el.nodeType == 1 ? el : this;
var val = $.trim(el.value)
}
To distingusih a DOM element do
if(el.nodeType)
精彩评论