isElement - determining if an object is an element
- From: "Aaron Gray" <ang.usenet@xxxxxxxxx>
- Date: Wed, 30 Jul 2008 14:46:35 +0100
Due to M$'s stupidity in not making DOMElements first class citizens the
following will not work :-
function isElement( o)
{
return o instanceof Element
}
It works for FF, Opera and Safari.
What prototype does is this :-
isElement: function(object) {
return object && object.nodeType == 1
}
My version used Browser sniffing :-
function isElement( o)
{
if (!isIE)
return o instanceof Element
else
return o && o.nodeType == 1 && o.tagName != undefined
}
Test case :-
http://www.aarongray.org/Test/JavaScript/isElement-test.html
The actual 'isIE' test code is not the best but is used for brevity.
Any crevats, problems or enhancements most welcome.
Thanks,
Aaron
.
- Follow-Ups:
- Prev by Date: .length is always 1
- Next by Date: Re: [OT] How to get rid of maniacs like Kamau Kambon? Filtersettings?
- Previous by thread: .length is always 1
- Next by thread: Re: isElement - determining if an object is an element
- Index(es):
Relevant Pages
|