I have a function were the input parameter can either be an
string,array,dom node or NodeList (getElementsByTagName()) and I have
somthing like this function which works great for what I want in every
case except if the pNd is the NodeList at which point I end up with the
nodeList in the first element of the array instead of acting like the
array would.
function doSomething(pNd){
if(pNd.constructor != Array){pNd = new Array(pNd)}
return pNd
}
So my question is how is there any easy way to figure out if pNd is a
NodeList ? When I use pNd.constructor on NodeList all I get is [object]
Thanks in advance.
Carl
Look into typeof
It will tell you what you are working with.
Eric
On 1/22/07, carlback <carlb@gmail.com> wrote:
> I have a function were the input parameter can either be an
> string,array,dom node or NodeList (getElementsByTagName()) and I have
> somthing like this function which works great for what I want in every
> case except if the pNd is the NodeList at which point I end up with the
> nodeList in the first element of the array instead of acting like the
> array would.
> function doSomething(pNd){
> if(pNd.constructor != Array){pNd = new Array(pNd)}
> return pNd
> }
> So my question is how is there any easy way to figure out if pNd is a
> NodeList ? When I use pNd.constructor on NodeList all I get is [object]
> Thanks in advance.
> Carl
On Jan 23, 2:47 am, "carlback" <carlb@gmail.com> wrote:
> So my question is how is there any easy way to figure out if pNd is a
> NodeList ? When I use pNd.constructor on NodeList all I get is [object]
Only can suggest to check whether the pNp supports NodeList methods,
like
if (pNp.item) {
...
}
Sincerely,
Alexander
http://www.alexatnet.com/ - PHP/Ajax tips, notes, tutorials