473,385 Members | 1,973 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Detecting NodeList object vs Array

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

Jan 23 '07 #1
2 5047
carlback wrote:
So my question is how is there any easy way to figure out if pNd is a
NodeList ?
You can detect the features of a NodeList instance, namely the length
property and the item method e.g.
if (typeof nodeList.length != 'undefined' && typeof nodeList.item !=
'undefined')
but such checks are supposed to check for those features to use them
safely if supported.
You seem to want to do something else with a node list, it is not clear
to me what.

--

Martin Honnen
http://JavaScript.FAQTs.com/
Jan 23 '07 #2

Martin Honnen wrote:
carlback wrote:
So my question is how is there any easy way to figure out if pNd is a
NodeList ?

You can detect the features of a NodeList instance, namely the length
property and the item method e.g.
In some browsers (Opera, Firefox):

if (nodeList instanceof NodeList) { ... }

does the trick - but that's perhaps not broad enough support for some.
:-)
--
Rob

Jan 23 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Morten Aune Lyrstad | last post by:
Here's the deal: I'm looping through a collection of listener class objects like this: (illustration code only) AClass::ThrowEvent() { for (int i = 0; i < numListeners; i++) {...
2
by: Howard Jess | last post by:
Given the html at the end of this message, I see how a DOM NodeList exhibits its "live" behavior; that is, adding elements to a document can change any NodeList variables, when there's *no* code...
8
by: Øyvind Jægtnes | last post by:
I'm playing around a bit with XPath and nodelist and i want to extract some info from a RSS feed. The one that i am testing at can be viewed at http://slashdot.org/index.rss Ok.. heres the deal:...
1
by: Chucker | last post by:
I would like to select some nodes from a very large XML document and then apply a stylesheet to the dom fragment / nodelist that is the result of my XPath-Query. It seems to me now that I have...
1
by: daniel | last post by:
Hi, Ignorant .Net Newbie Here - I'm loading up an XML document and trying to encrypt some elements but not others, by iterating through the nodelist returned from...
1
by: Shem | last post by:
Hi Folks, I have written a small webservice in which one of the methods returns a nodelist. The file compiles OK, but when I ry to run it I ge teh following error: "You must implement the...
1
by: DP413 | last post by:
Hey guys need your help :) I'm trying to clone a nodelist in a bookmarklet so that I can use document.write to output each item in the nodelist to the browser. Right now I'm basically grabbing...
2
by: sndive | last post by:
i extract class object from an instance of NodeList (minicompat.py) like so PyObject *pclass = PyObject_GetAttrString( nodelistinsance, "__class__"); but PyObject_GetAttrString(pclass,...
15
Dormilich
by: Dormilich | last post by:
I’m trying to do the following document.getElementsByTagName("sup").getElementsByTagName("a"); currently I have this because I somehow need to return a combined result NodeList // can’t prototype...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.