Re: isElement - determining if an object is an element
- From: "Aaron Gray" <ang.usenet@xxxxxxxxx>
- Date: Thu, 31 Jul 2008 01:40:07 +0100
"RobG" <rgqld@xxxxxxxxxxxx> wrote in message news:57e97d0b-33f7-4198-b0ae-e9dc04dc4e36@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
On Jul 30, 11:46 pm, "Aaron Gray" <ang.use...@xxxxxxxxx> wrote:
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
}
<Noting the other advice given here, and that IE 8 will not support
<enumeration of nodeType constant values, the following should suit
<
<function isElement(o) {
< return o && o.nodeType &&
< (o.ELEMENT_NODE === o.nodeType || o.nodeType === 1);
<}
This is messy. My code worked fine on IE8. BTW Just removed IE8 due to other issues, like behavioual bugs.
<Given that you are really trying to distinguish between a DOM node and
<a JSON string, why not:
Its not a JSON string but an diseminated object at this stage that comes from a JSON object.
Thanks,
Aaron
.
- Follow-Ups:
- References:
- isElement - determining if an object is an element
- From: Aaron Gray
- Re: isElement - determining if an object is an element
- From: RobG
- isElement - determining if an object is an element
- Prev by Date: Re: isElement - determining if an object is an element
- Next by Date: Re: isElement - determining if an object is an element
- Previous by thread: Re: isElement - determining if an object is an element
- Next by thread: Re: isElement - determining if an object is an element
- Index(es):
Relevant Pages
|