Login Register Help
API Documentation
Choose a stylesheet:

Constructordojo.NodeList

dojo.NodeList instances provide many utilities that reflect core Dojo APIs for Array iteration and manipulation, DOM manipulation, and event handling. Instead of needing to dig up functions in the dojo.* namespace, NodeLists generally make the full power of Dojo available for DOM manipulation tasks in a simple, chainable way.

Examples

Example 1

create a node list from a node

new dojo.NodeList(dojo.byId("foo"));

Example 2

get a NodeList from a CSS query and iterate on it

var l = dojo.query(".thinger");
l.forEach(function(node, index, nodeList){
    console.log(index, node.innerHTML);
});

Example 3

use native and Dojo-provided array methods to manipulate a NodeList without needing to use dojo.* functions explicitly:

var l = dojo.query(".thinger");
// since NodeLists are real arrays, they have a length
// property that is both readable and writable and
// push/pop/shift/unshift methods
console.log(l.length);
l.push(dojo.create("<span>howdy!</span>"));
 
 
// dojo's normalized array methods work too:
console.log( l.indexOf(dojo.byId("foo")) );
// ...including the special "function as string" shorthand
console.log( l.every("item.nodeType == 1") );
 
 
// NodeLists can be [..] indexed, or you can use the at()
// function to get specific items wrapped in a new NodeList:
var node = l[3]; // the 4th element
var newList = l.at(1, 3); // the 2nd and 4th elements

Example 4

the style functions you expect are all there too:

// style() as a getter...
var borders = dojo.query(".thinger").style("border");
// ...and as a setter:
dojo.query(".thinger").style("border", "1px solid black");
// class manipulation
dojo.query("li:nth-child(even)").addClass("even");
// even getting the coordinates of all the items
var coords = dojo.query(".thinger").coords();

Example 5

DOM manipulation functions from the dojo.* namespace area also available:

// remove all of the elements in the list from their
// parents (akin to "deleting" them from the document)
dojo.query(".thinger").orphan();
// place all elements in the list at the front of #foo
dojo.query(".thinger").place("foo", "first");

Example 6

Event handling couldn’t be easier. dojo.connect is mapped in, and shortcut handlers are provided for most DOM events:

// like dojo.connect(), but with implicit scope
dojo.query("li").connect("onclick", console, "log");
 
 
// many common event handlers are already available directly:
dojo.query("li").onclick(console, "log");
var toggleHovered = dojo.hitch(dojo, "toggleClass", "hovered");
dojo.query("p")
    .onmouseenter(toggleHovered)
    .onmouseleave(toggleHovered);

Example 7

chainability is a key advantage of NodeLists:

dojo.query(".thinger")
    .onclick(function(e){ /* ... */ })
    .at(1, 3, 8) // get a subset
        .style("padding", "5px")
        .forEach(console.log);

Jump to PropertiesJump to FunctionsNamespacesBack to top

add a node or some HTML as a string to every item in the list. Returns the original list.
gets or sets the DOM attribute for every element in the NodeList
gets or sets the CSS property for every element in the NodeList

Jump to PropertiesJump to NamespacesFunctionsBack to top

Overrides
adds the specified class to every node in the list
Functionadopt(queryOrListOrNode: String|Array|DomNode, position: String?): dojo.NodeList
Overrides
places any/all elements in queryOrListOrNode at a position relative to the first element in this list. Returns a dojo.NodeList of the adopted elements.
Functionanim(properties: Object, duration: Integer?, easing: Function?, onEnd: Function?, delay: Integer?): dojo._Animation
Overrides
Animate one or more CSS properties for all nodes in this list. The returned animation object will already be playing when it is returned. See the docs for dojo.anim for full details.
Overrides
see dojo.animateProperty(). Animate all elements of this NodeList across the properties specified.
Overrides
Returns a new NodeList comprised of items in this NodeList at the given index or indices.
Overrides
Returns a new NodeList comprised of items in this NodeList as well as items passed in as parameters
Functionconnect(methodName: String, objOrFunc: Object|Function|String, funcName: String?)
Overrides
attach event handlers to every item of the NodeList. Uses dojo.connect() so event properties are normalized
Overrides
Returns the box objects all elements in a node list as an Array (*not* a NodeList)
Functiondtl(template: dojox.dtl.__StringArgs|String, context: dojox.dtl.__ObjectArgs|Object)
Overrides
Overrides
clears all content from each node in the list. Effectively equivalent to removing all child nodes from every item in the list.
Functionevery(callback: Function:, thisObject: Object:?): Boolean
Overrides
see dojo.every() and the (Array.every docs)[http://developer.mozilla.org/en/docs/Core_JavaScript_1.5_Reference:Global_Objects:Array:every]. Takes the same structure of arguments and returns as dojo.every() with the caveat that the passed array is implicitly this NodeList
Overrides
fade in all elements of this NodeList. Returns an instance of dojo._Animation
Overrides
fade out all elements of this NodeList. Returns an instance of dojo._Animation
FunctionfadeTo(args)
Overrides
fade all elements of the node list to a specified opacity
Overrides
"masks" the built-in javascript filter() method (supported in Dojo via dojo.filter) to support passing a simple string filter in addition to supporting filtering function objects.
FunctionforEach(callback, thisObj): dojo.NodeList
Overrides
see dojo.forEach(). The primary difference is that the acted-on array is implicitly this NodeList
Overrides
highlight all elements of the node list. Returns an instance of dojo._Animation
Functionhtml(content, params: Object?): dojo.NodeList
Overrides
see dojo.html.set(). Set the content of all elements of this NodeList
FunctionindexOf(value: Object:, fromIndex: Integer:?): Integer
Overrides
see dojo.indexOf(). The primary difference is that the acted-on array is implicitly this NodeList
Functioninstantiate(declaredClass: String|Object, properties: Object?): dojo.NodeList
Overrides
Create a new instance of a specified class, using the specified properties and each node in the nodeList as a srcNodeRef
FunctionlastIndexOf(value: Object, fromIndex: Integer?): Integer
Overrides
see dojo.lastIndexOf(). The primary difference is that the acted-on array is implicitly this NodeList
Overrides
see dojo.map(). The primary difference is that the acted-on array is implicitly this NodeList and the return is a dojo.NodeList (a subclass of Array) /return d.map(this, func, obj, d.NodeList); // dojo.NodeList
Functionorphan(simpleFilter: String?): dojo.NodeList
Overrides
removes elements in this list that match the simple filter from their parents and returns them as a new NodeList.
Functionplace(queryOrNode: String|Node, position: String): dojo.NodeList
Overrides
places elements of this node list relative to the first element matched by queryOrNode. Returns the original NodeList. See: dojo.place
Overrides
Returns a new list whose memebers match the passed query, assuming elements of the current NodeList as the root for each search.
Overrides
removes the specified class from every node in the list
Overrides
size all elements of this NodeList. Returns an instance of dojo._Animation
Functionslice(begin: Integer, end: Integer?)
Overrides
Returns a new NodeList, maintaining this one in place
Overrides
slide all elements of this NodeList. Returns an instance of dojo._Animation
Overrides
slide all elements of the node list to the specified place. Returns an instance of dojo._Animation
Functionsome(callback: Function:, thisObject: Object:?): Boolean
Overrides
Takes the same structure of arguments and returns as dojo.some() with the caveat that the passed array is implicitly this NodeList. See dojo.some() and Mozilla's (Array.some documentation)[http://developer.mozilla.org/en/docs/Core_JavaScript_1.5_Reference:Global_Objects:Array:some].
Functionsplice(index: Integer, howmany: Integer?, item: Object?)
Overrides
Returns a new NodeList, manipulating this NodeList based on the arguments passed, potentially splicing in new elements at an offset, optionally deleting elements
FunctiontoggleClass(className: String, condition: Boolean?): dojo.NodeList
Overrides
Adds a class to node if not present, or removes if present. Pass a boolean condition if you want to explicitly add or remove.
Overrides
wipe in all elements of this NodeList. Returns an instance of dojo._Animation
Overrides
wipe out all elements of this NodeList. Returns an instance of dojo._Animation
FunctionwipeTo(args)
Overrides
Wipe all elements of the NodeList to a specified width: or height:
Function_anim(obj, method, args)
Overrides

Jump to FunctionsJump to NamespacesPropertiesBack to top