Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Javascript, viewing "object nodelist"

Doing an alert() on one of my variables gives me this result

  [object NodeList]

How can I see all the values in that?

Note; I am on Firefox and dont know how to use chromebug so its not installed.

like image 842
Ryan Avatar asked Jul 30 '11 02:07

Ryan


People also ask

What is a nodelist object in JavaScript?

Jump to: NodeList objects are collections of nodes, usually returned by properties such as Node.childNodes and methods such as document.querySelectorAll(). Although NodeList is not an Array, it is possible to iterate over it with forEach().

How to go through all the values in a nodelist?

The NodeList.values () method returns an iterator allowing to go through all values contained in this object. The values are Node objects. Returns an iterator. The compatibility table on this page is generated from structured data.

How do you access a node in a node list?

NodeList items can only be accessed by their index number. Only the NodeList object can contain attribute nodes and text nodes. A node list is not an array! A node list may look like an array, but it is not. You can loop through the node list and refer to its nodes like an array.

What is the use of return in nodelist?

Returns an item in the list by its index, or null if the index is out-of-bounds. An alternative to accessing nodeList [i] (which instead returns undefined when i is out-of-bounds). This is mostly useful for non-JavaScript DOM implementations. Returns an iterator, allowing code to go through all key/value pairs contained in the collection.


1 Answers

You can iterate the values in a NodeList the same way you would an array:

for (var index = 0; index < nodeList.length; index++) {
    alert(nodeList[index]);
}

Here is a good resource with some more in-depth information: https://web.archive.org/web/20170119045716/http://reference.sitepoint.com/javascript/NodeList

like image 174
aroth Avatar answered Sep 29 '22 01:09

aroth