dojo/NodeList (version 1.8)

Array-like object which adds syntactic sugar for chaining, common iteration operations, animation, and node manipulation. NodeLists are most often returned as the result of dojo.query() calls.

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.

Usage

NodeList(array);
ParameterTypeDescription
arrayundefined
Returns: Array

Examples

Example 1

create a node list from a node

new query.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"));

// 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);

Property Summary

Method Summary

  • _adaptAsFilter(f, o) adapts a single node function to be used in the filter-type actions
  • _adaptAsForEach(f, o) adapts a single node function to be used in the forEach-type actions.
  • _adaptAsMap(f, o) adapts a single node function to be used in the map-type actions.
  • _adaptWithCondition(f, g, o) adapts a single node function to be used in the map-type actions, behaves like forEach() or map() depending on arguments
  • _anim(obj, method, args)
  • _buildArrayFromCallback(callback) builds a new array of possibly differing size based on the input list.
  • _cloneNode(node) private utility to clone a node.
  • _getRelatedUniqueNodes(query, callback) cycles over all the nodes and calls a callback to collect nodes for a possible inclusion in a result.
  • _getUniqueAsNodeList(nodes) given a list of nodes, make sure only unique elements are returned as our NodeList object.
  • _getUniqueNodeListWithParent(nodes, query) gets unique element nodes, filters them further with an optional query and then calls _stash to track parent NodeList.
  • _NodeListCtor(array) Array-like object which adds syntactic sugar for chaining, common iteration operations, animation, and node manipulation. NodeLists are most often returned as the result of dojo.query() calls.
  • _normalize(content, refNode) normalizes data to an array of items to insert.
  • _place(ary, refNode, position, useClone) private utility to handle placing an array of nodes relative to another node.
  • _placeMultiple(query, position) private method for inserting queried nodes into all nodes in this NodeList at different positions.
  • _stash(parent) private function to hold to a parent NodeList. end() to return the parent NodeList.
  • _wrap(a, parent, NodeListCtor) decorate an array to make it look like a dojo/NodeList.
  • addClass(className) adds the specified class to every node in the list
  • addClassFx(cssClass, args) Animate the effects of adding a class to all nodes in this list. see dojox.fx.addClass
  • addContent(content, position) add a node, NodeList or some HTML as a string to every item in the list. Returns the original list.
  • adopt(queryOrListOrNode, position) places any/all elements in queryOrListOrNode at a position relative to the first element in this list.
  • after(content) Places the content after every node in the NodeList.
  • andSelf() Adds the nodes from the previous dojo/NodeList to the current dojo/NodeList.
  • anim(properties, duration, easing, onEnd, delay) Animate one or more CSS properties for all nodes in this list.
  • animateProperty(args) Animate all elements of this NodeList across the properties specified. syntax identical to dojo.animateProperty
  • append(content) appends the content to every node in the NodeList.
  • appendTo(query) appends nodes in this NodeList to the nodes matched by the query passed to appendTo.
  • at(index) Returns a new NodeList comprised of items in this NodeList at the given index or indices.
  • attr(property, value) gets or sets the DOM attribute for every element in the NodeList.
  • before(content) Places the content before every node in the NodeList.
  • children(query) Returns all immediate child elements for nodes in this dojo/NodeList. Optionally takes a query to filter the child elements.
  • clone() Clones all the nodes in this NodeList and returns them as a new NodeList.
  • closest(query, root) Returns closest parent that matches query, including current node in this dojo/NodeList if it matches the query.
  • concat(item) Returns a new NodeList comprised of items in this NodeList as well as items passed in as parameters
  • connect(methodName, objOrFunc, funcName) Attach event handlers to every item of the NodeList.
  • coords() Deprecated: Use position() for border-box x/y/w/h or marginBox() for margin-box w/h/l/t.
  • data(key, value) stash or get some arbitrary data on/from these nodes.
  • delegate(selector, eventName, fn) Monitor nodes in this NodeList for [bubbled] events on nodes that match selector. Calls fn(evt) for those events, where (inside of fn()), this == the node that matches the selector.
  • dtl(template, context) Renders the specified template in each of the NodeList entries.
  • empty() clears all content from each node in the list.
  • end() Ends use of the current NodeList by returning the previous NodeList that generated the current NodeList.
  • even() Returns the even nodes in this dojo/NodeList as a dojo/NodeList.
  • every(callback, thisObject) see dojo.every() and the Array.every docs.
  • fadeIn(args) fade in all elements of this NodeList via dojo.fadeIn
  • fadeOut(args) fade out all elements of this NodeList via dojo.fadeOut
  • filter(filter) "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.
  • first() Returns the first node in this dojo/NodeList as a dojo/NodeList.
  • forEach(callback, thisObj) see dojo.forEach().
  • html(value) allows setting the innerHTML of each node in the NodeList, if there is a value passed in, otherwise, reads the innerHTML value of the first node.
  • indexOf(value, fromIndex) see dojo.indexOf(). The primary difference is that the acted-on array is implicitly this NodeList
  • innerHTML(value) allows setting the innerHTML of each node in the NodeList, if there is a value passed in, otherwise, reads the innerHTML value of the first node.
  • insertAfter(query) The nodes in this NodeList will be placed after the nodes matched by the query passed to insertAfter.
  • insertBefore(query) The nodes in this NodeList will be placed after the nodes matched by the query passed to insertAfter.
  • instantiate(declaredClass, properties) Create a new instance of a specified class, using the specified properties and each node in the NodeList as a srcNodeRef.
  • last() Returns the last node in this dojo/NodeList as a dojo/NodeList.
  • lastIndexOf(value, fromIndex) see dojo.lastIndexOf(). The primary difference is that the acted-on array is implicitly this NodeList
  • map(func, obj) see dojo.map().
  • marginBox() Returns margin-box size of nodes
  • next(query) Returns the next element for nodes in this dojo/NodeList. Optionally takes a query to filter the next elements.
  • nextAll(query) Returns all sibling elements that come after the nodes in this dojo/NodeList. Optionally takes a query to filter the sibling elements.
  • odd() Returns the odd nodes in this dojo/NodeList as a dojo/NodeList.
  • on(eventName, listener) Listen for events on the nodes in the NodeList.
  • orphan(filter) removes elements in this list that match the filter from their parents and returns them as a new NodeList.
  • parent(query) Returns immediate parent elements for nodes in this dojo/NodeList. Optionally takes a query to filter the parent elements.
  • parents(query) Returns all parent elements for nodes in this dojo/NodeList. Optionally takes a query to filter the child elements.
  • place(queryOrNode, position) places elements of this node list relative to the first element matched by queryOrNode.
  • position() Returns border-box objects (x/y/w/h) of all elements in a node list as an Array (not a NodeList).
  • prepend(content) prepends the content to every node in the NodeList.
  • prependTo(query) prepends nodes in this NodeList to the nodes matched by the query passed to prependTo.
  • prev(query) Returns the previous element for nodes in this dojo/NodeList. Optionally takes a query to filter the previous elements.
  • prevAll(query) Returns all sibling elements that come before the nodes in this dojo/NodeList. Optionally takes a query to filter the sibling elements.
  • query(queryStr) Returns a new list whose members match the passed query, assuming elements of the current NodeList as the root for each search.
  • remove(filter) removes elements in this list that match the filter from their parents and returns them as a new NodeList.
  • removeAttr(name) Removes an attribute from each node in the list.
  • removeClass(className) removes the specified class from every node in the list
  • removeClassFx(cssClass, args) Animate the effect of removing a class to all nodes in this list. see dojox.fx.removeClass
  • removeData(key) Remove the data associated with these nodes.
  • replaceAll(query) replaces nodes matched by the query passed to replaceAll with the nodes in this NodeList.
  • replaceClass(addClassStr, removeClassStr) Replaces one or more classes on a node if not present.
  • replaceWith(content) Replaces each node in ths NodeList with the content passed to replaceWith.
  • siblings(query) Returns all sibling elements for nodes in this dojo/NodeList. Optionally takes a query to filter the sibling elements.
  • slice(begin, end) Returns a new NodeList, maintaining this one in place
  • slideTo(args) slide all elements of the node list to the specified place via dojo/fx.slideTo()
  • some(callback, thisObject) Takes the same structure of arguments and returns as dojo.some() with the caveat that the passed array is implicitly this NodeList.
  • splice(index, howmany, item) Returns a new NodeList, manipulating this NodeList based on the arguments passed, potentially splicing in new elements at an offset, optionally deleting elements
  • style(property, value) gets or sets the CSS property for every element in the NodeList
  • text(value) allows setting the text value of each node in the NodeList, if there is a value passed in, otherwise, returns the text value for all the nodes in the NodeList in one string.
  • toggleClass(className, condition) Adds a class to node if not present, or removes if present.
  • toggleClassFx(cssClass, force, args) Animate the effect of adding or removing a class to all nodes in this list. see dojox.fx.toggleClass
  • toString()
  • val(value) If a value is passed, allows seting the value property of form elements in this NodeList, or properly selecting/checking the right value for radio/checkbox/select elements.
  • wipeIn(args) wipe in all elements of this NodeList via dojo/fx.wipeIn()
  • wipeOut(args) wipe out all elements of this NodeList via dojo/fx.wipeOut()
  • wrap(html) Wrap each node in the NodeList with html passed to wrap.
  • wrapAll(html) Insert html where the first node in this NodeList lives, then place all nodes in this NodeList as the child of the html.
  • wrapInner(html) For each node in the NodeList, wrap all its children with the passed in html.

Properties

events

Methods

_adaptAsFilter(f, o)
Defined by dojo/query

adapts a single node function to be used in the filter-type actions

ParameterTypeDescription
fFunction

a function to adapt

oObject
Optional.

an optional context for f

Returns: function
_adaptAsForEach(f, o)
Defined by dojo/query

adapts a single node function to be used in the forEach-type actions. The initial object is returned from the specialized function.

ParameterTypeDescription
fFunction

a function to adapt

oObject
Optional.

an optional context for f

Returns: function
_adaptAsMap(f, o)
Defined by dojo/query

adapts a single node function to be used in the map-type actions. The return is a new array of values, as via dojo.map

ParameterTypeDescription
fFunction

a function to adapt

oObject
Optional.

an optional context for f

Returns: function
_adaptWithCondition(f, g, o)
Defined by dojo/query

adapts a single node function to be used in the map-type actions, behaves like forEach() or map() depending on arguments

ParameterTypeDescription
fFunction

a function to adapt

gFunction

a condition function, if true runs as map(), otherwise runs as forEach()

oObject
Optional.

an optional context for f and g

Returns: function
_anim(obj, method, args)
Defined by dojo/NodeList-fx
ParameterTypeDescription
objundefined
methodundefined
argsundefined
Returns: undefined
_buildArrayFromCallback(callback)

builds a new array of possibly differing size based on the input list. Since the returned array is likely of different size than the input array, the array's map function cannot be used.

ParameterTypeDescription
callbackFunction
Returns: undefined
_cloneNode(node)

private utility to clone a node. Not very interesting in the vanilla dojo/NodeList case, but delegates could do interesting things like clone event handlers if that is derivable from the node.

ParameterTypeDescription
nodeDOMNode
Returns: undefined
_getRelatedUniqueNodes(query, callback)

cycles over all the nodes and calls a callback to collect nodes for a possible inclusion in a result. The callback will get two args: callback(node, ary), where ary is the array being used to collect the nodes.

ParameterTypeDescription
queryString
Optional.
callbackFunction
Returns: undefined
_getUniqueAsNodeList(nodes)

given a list of nodes, make sure only unique elements are returned as our NodeList object. Does not call _stash().

ParameterTypeDescription
nodesArray
Returns: undefined
_getUniqueNodeListWithParent(nodes, query)

gets unique element nodes, filters them further with an optional query and then calls _stash to track parent NodeList.

ParameterTypeDescription
nodesArray
queryString
Returns: undefined
_NodeListCtor(array)
Defined by dojo/query

Array-like object which adds syntactic sugar for chaining, common iteration operations, animation, and node manipulation. NodeLists are most often returned as the result of dojo.query() calls.

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.

ParameterTypeDescription
arrayundefined
Returns: Array
Example 1

create a node list from a node

new query.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"));

// 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);
_normalize(content, refNode)

normalizes data to an array of items to insert.

If content is an object, it can have special properties "template" and "parse". If "template" is defined, then the template value is run through dojo.string.substitute (if dojo/string.substitute() has been dojo.required elsewhere), or if templateFunc is a function on the content, that function will be used to transform the template into a final string to be used for for passing to dojo/dom-construct.toDom(). If content.parse is true, then it is remembered for later, for when the content nodes are inserted into the DOM. At that point, the nodes will be parsed for widgets (if dojo.parser has been dojo.required elsewhere).

ParameterTypeDescription
contentString | Element | Object | NodeList
refNodeDOMNode
Optional.
Returns: undefined
_place(ary, refNode, position, useClone)

private utility to handle placing an array of nodes relative to another node.

Allows for cloning the nodes in the array, and for optionally parsing widgets, if ary._runParse is true.

ParameterTypeDescription
aryArray
refNodeDOMNode
positionString
useCloneBoolean
_placeMultiple(query, position)

private method for inserting queried nodes into all nodes in this NodeList at different positions. Differs from NodeList.place because it will clone the nodes in this NodeList if the query matches more than one element.

ParameterTypeDescription
queryString | Node | NodeList
positionString
Returns: function

private method for inserting queried nodes into all nodes in this NodeList at different positions. Differs from NodeList.place because it will clone the nodes in this NodeList if the query matches more than one element.

_stash(parent)
Defined by dojo/query

private function to hold to a parent NodeList. end() to return the parent NodeList.

ParameterTypeDescription
parentundefined
Returns: function

private function to hold to a parent NodeList. end() to return the parent NodeList.

Example

How to make a dojo/NodeList method that only returns the third node in the dojo/NodeList but allows access to the original NodeList by using this._stash:

dojo.extend(NodeList, {
    third: function(){
        var newNodeList = NodeList(this[2]);
        return newNodeList._stash(this);
    }
});
// then see how _stash applies a sub-list, to be .end()'ed out of
dojo.query(".foo")
    .third()
        .addClass("thirdFoo")
    .end()
    // access to the orig .foo list
    .removeClass("foo")
_wrap(a, parent, NodeListCtor)
Defined by dojo/query

decorate an array to make it look like a dojo/NodeList.

ParameterTypeDescription
aArray

Array of nodes to decorate.

parentdojo/NodeList
Optional.

An optional parent NodeList that generated the current list of nodes. Used to call _stash() so the parent NodeList can be accessed via end() later.

NodeListCtorFunction
Optional.

An optional constructor function to use for any new NodeList calls. This allows a certain chain of NodeList calls to use a different object than dojo/NodeList.

Returns: instance
addClass(className)

adds the specified class to every node in the list

ParameterTypeDescription
classNameString | Array

A String class name to add, or several space-separated class names, or an array of class names.

addClassFx(cssClass, args)

Animate the effects of adding a class to all nodes in this list. see dojox.fx.addClass

ParameterTypeDescription
cssClassundefined
argsundefined
Returns: [object Value(type: function, value: undefined)]
Example
// fade all elements with class "bar" to to 50% opacity
dojo.query(".bar").addClassFx("bar").play();
addContent(content, position)

add a node, NodeList or some HTML as a string to every item in the list. Returns the original list.

a copy of the HTML content is added to each item in the list, with an optional position argument. If no position argument is provided, the content is appended to the end of each item.

ParameterTypeDescription
contentString | DomNode | Object | dojo/NodeList

the content to be set on the parent element. This can be an html string, a node reference or a NodeList, dojo/NodeList, Array or other enumerable list of nodes

positionString | Integer
Optional.

can be one of:

  • "last"||"end" (default)
  • "first||"start"
  • "before"
  • "after"
  • "replace" (replaces nodes in this NodeList with new content)
  • "only" (removes other children of the nodes so new content is the only child)

or an offset in the childNodes property

Returns: function

add a node, NodeList or some HTML as a string to every item in the list. Returns the original list.

Example 1

appends content to the end if the position is omitted

dojo.query("h3 > p").addContent("hey there!");
Example 2

add something to the front of each element that has a "thinger" property:

dojo.query("[thinger]").addContent("...", "first");
Example 3

adds a header before each element of the list

dojo.query(".note").addContent("<h4>NOTE:</h4>", "before");
Example 4

add a clone of a DOM node to the end of every element in the list, removing it from its existing parent.

dojo.query(".note").addContent(dojo.byId("foo"));
Example 5

Append nodes from a templatized string.

dojo.require("dojo.string");
dojo.query(".note").addContent({
    template: '<b>${id}: </b><span>${name}</span>',
    id: "user332",
    name: "Mr. Anderson"
});
Example 6

Append nodes from a templatized string that also has widgets parsed.

dojo.require("dojo.string");
dojo.require("dojo.parser");
var notes = dojo.query(".note").addContent({
    template: '<button dojoType="dijit/form/Button">${text}</button>',
    parse: true,
    text: "Send"
});
adopt(queryOrListOrNode, position)

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.

ParameterTypeDescription
queryOrListOrNodeString | Array | DomNode

a DOM node or a query string or a query result. Represents the nodes to be adopted relative to the first element of this NodeList.

positionString
Optional.

can be one of:

  • "last" (default)
  • "first"
  • "before"
  • "after"
  • "only"
  • "replace"

or an offset in the childNodes property

Returns: undefined
after(content)

Places the content after every node in the NodeList.

The content will be cloned if the length of NodeList is greater than 1. Only the DOM nodes are cloned, not any attached event handlers.

ParameterTypeDescription
contentString | Element | NodeList
Returns: any | undefined

dojo/NodeList, the nodes currently in this NodeList will be returned, not the appended content.

Example

assume a DOM created by this markup:

<div id="foo"><p>Hello Mars</p></div>
<div id="bar"><p>Hello World</p></div>

Running this code:

dojo.query("div").after("<span>after</span>");

Results in this DOM structure:

<div id="foo"><p>Hello Mars</p></div><span>after</span>
<div id="bar"><p>Hello World</p></div><span>after</span>
andSelf()

Adds the nodes from the previous dojo/NodeList to the current dojo/NodeList.

.end() can be used on the returned dojo/NodeList to get back to the original dojo/NodeList.

Returns: undefined
Example

assume a DOM created by this markup:

<div class="container">
    <div class="red prev">Red One</div>
    Some Text
    <div class="blue prev">Blue One</div>
    <div class="red second">Red Two</div>
    <div class="blue">Blue Two</div>
</div>

Running this code:

dojo.query(".second").prevAll().andSelf();

returns the two divs with class of "prev", as well as the div with class "second".

anim(properties, duration, easing, onEnd, delay)
Defined by dojo/NodeList-fx

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.

ParameterTypeDescription
propertiesObject

the properties to animate. does NOT support the auto parameter like other NodeList-fx methods.

durationInteger
Optional.

Optional. The time to run the animations for

easingFunction
Optional.

Optional. The easing function to use.

onEndFunction
Optional.

A function to be called when the animation ends

delayInteger
Optional.

how long to delay playing the returned animation

Returns: undefined
Example 1

Another way to fade out:

dojo.query(".thinger").anim({ opacity: 0 });
Example 2

animate all elements with the "thigner" class to a width of 500 pixels over half a second

dojo.query(".thinger").anim({ width: 500 }, 700);
animateProperty(args)
Defined by dojo/NodeList-fx

Animate all elements of this NodeList across the properties specified. syntax identical to dojo.animateProperty

ParameterTypeDescription
argsObject
Optional.

Additional dojo/_base/fx.Animation arguments to mix into this set with the addition of an auto parameter.

Returns: dojo/_base/fx.Animation | dojo/NodeList | undefined

A special args member auto can be passed to automatically play the animation. If args.auto is present, the original dojo/NodeList will be returned for further chaining. Otherwise the dojo/_base/fx.Animation instance is returned and must be .play()'ed

Example 1
dojo.query(".zork").animateProperty({
    duration: 500,
    properties: {
        color:      { start: "black", end: "white" },
        left:       { end: 300 }
    }
}).play();
Example 2
dojo.query(".grue").animateProperty({
    auto:true,
    properties: {
        height:240
    }
}).onclick(handler);
append(content)

appends the content to every node in the NodeList.

The content will be cloned if the length of NodeList is greater than 1. Only the DOM nodes are cloned, not any attached event handlers.

ParameterTypeDescription
contentString | DOMNode | NodeList
Returns: any | undefined

dojo/NodeList, the nodes currently in this NodeList will be returned, not the appended content.

Example

assume a DOM created by this markup:

<div id="foo"><p>Hello Mars</p></div>
<div id="bar"><p>Hello World</p></div>

Running this code:

dojo.query("div").append("<span>append</span>");

Results in this DOM structure:

<div id="foo"><p>Hello Mars</p><span>append</span></div>
<div id="bar"><p>Hello World</p><span>append</span></div>
appendTo(query)

appends nodes in this NodeList to the nodes matched by the query passed to appendTo.

The nodes in this NodeList will be cloned if the query matches more than one element. Only the DOM nodes are cloned, not any attached event handlers.

ParameterTypeDescription
queryString
Returns: any | undefined

dojo/NodeList, the nodes currently in this NodeList will be returned, not the matched nodes from the query.

Example

assume a DOM created by this markup:

<span>append</span>
<p>Hello Mars</p>
<p>Hello World</p>

Running this code:

dojo.query("span").appendTo("p");

Results in this DOM structure:

<p>Hello Mars<span>append</span></p>
<p>Hello World<span>append</span></p>
at(index)
Defined by dojo/query

Returns a new NodeList comprised of items in this NodeList at the given index or indices.

ParameterTypeDescription
indexInteger...

One or more 0-based indices of items in the current NodeList. A negative index will start at the end of the list and go backwards.

Returns: undefined
Example 1

Shorten the list to the first, second, and third elements

query("a").at(0, 1, 2).forEach(fn);
Example 2

Retrieve the first and last elements of a unordered list:

query("ul > li").at(0, -1).forEach(cb);
Example 3

Do something for the first element only, but end() out back to the original list and continue chaining:

query("a").at(0).onclick(fn).end().forEach(function(n){
    console.log(n); // all anchors on the page.
})
attr(property, value)

gets or sets the DOM attribute for every element in the NodeList. See also dojo.attr

ParameterTypeDescription
propertyString

the attribute to get/set

valueString
Optional.

optional. The value to set the property to

Returns: any

if no value is passed, the result is an array of attribute values If a value is passed, the return is this NodeList

Example 1

Make all nodes with a particular class focusable:

dojo.query(".focusable").attr("tabIndex", -1);
Example 2

Disable a group of buttons:

dojo.query("button.group").attr("disabled", true);
Example 3

innerHTML can be assigned or retrieved as well:

// get the innerHTML (as an array) for each list item
var ih = dojo.query("li.replaceable").attr("innerHTML");
before(content)

Places the content before every node in the NodeList.

The content will be cloned if the length of NodeList is greater than 1. Only the DOM nodes are cloned, not any attached event handlers.

ParameterTypeDescription
contentString | DOMNode | NodeList
Returns: any | undefined

dojo/NodeList, the nodes currently in this NodeList will be returned, not the appended content.

Example

assume a DOM created by this markup:

<div id="foo"><p>Hello Mars</p></div>
<div id="bar"><p>Hello World</p></div>

Running this code:

dojo.query("div").before("<span>before</span>");

Results in this DOM structure:

<span>before</span><div id="foo"><p>Hello Mars</p></div>
<span>before</span><div id="bar"><p>Hello World</p></div>
children(query)

Returns all immediate child elements for nodes in this dojo/NodeList. Optionally takes a query to filter the child elements.

.end() can be used on the returned dojo/NodeList to get back to the original dojo/NodeList.

ParameterTypeDescription
queryString
Optional.

a CSS selector.

Returns: any | undefined

all immediate child elements for the nodes in this dojo/NodeList.

Example

assume a DOM created by this markup:

<div class="container">
    <div class="red">Red One</div>
    Some Text
    <div class="blue">Blue One</div>
    <div class="red">Red Two</div>
    <div class="blue">Blue Two</div>
</div>

Running this code:

dojo.query(".container").children();

returns the four divs that are children of the container div.

Running this code:

dojo.query(".container").children(".red");

returns the two divs that have the class "red".

clone()

Clones all the nodes in this NodeList and returns them as a new NodeList.

Only the DOM nodes are cloned, not any attached event handlers.

Returns: any | undefined

a cloned set of the original nodes.

Example

assume a DOM created by this markup:

<div class="container">
    <div class="red">Red One</div>
    <div class="blue">Blue One</div>
    <div class="red">Red Two</div>
    <div class="blue">Blue Two</div>
</div>

Running this code:

dojo.query(".red").clone().appendTo(".container");

Results in this DOM structure:

<div class="container">
    <div class="red">Red One</div>
    <div class="blue">Blue One</div>
    <div class="red">Red Two</div>
    <div class="blue">Blue Two</div>
    <div class="red">Red One</div>
    <div class="red">Red Two</div>
</div>
closest(query, root)

Returns closest parent that matches query, including current node in this dojo/NodeList if it matches the query.

.end() can be used on the returned dojo/NodeList to get back to the original dojo/NodeList.

ParameterTypeDescription
queryString

a CSS selector.

rootString | DOMNode
Optional.

If specified, query is relative to "root" rather than document body.

Returns: any | undefined

the closest parent that matches the query, including the current node in this dojo/NodeList if it matches the query.

Example

assume a DOM created by this markup:

<div class="container">
    <div class="red">Red One</div>
    Some Text
    <div class="blue">Blue One</div>
    <div class="red">Red Two</div>
    <div class="blue">Blue Two</div>
</div>

Running this code:

dojo.query(".red").closest(".container");

returns the div with class "container".

concat(item)
Defined by dojo/query

Returns a new NodeList comprised of items in this NodeList as well as items passed in as parameters

This method behaves exactly like the Array.concat method with the caveat that it returns a NodeList and not a raw Array. For more details, see the Array.concat docs

ParameterTypeDescription
itemObject
Optional.

Any number of optional parameters may be passed in to be spliced into the NodeList

Returns: undefined
connect(methodName, objOrFunc, funcName)

Attach event handlers to every item of the NodeList. Uses dojo.connect() so event properties are normalized.

Application must manually require() "dojo/_base/connect" before using this method.

ParameterTypeDescription
methodNameString

the name of the method to attach to. For DOM events, this should be the lower-case name of the event

objOrFuncObject | Function | String

if 2 arguments are passed (methodName, objOrFunc), objOrFunc should reference a function or be the name of the function in the global namespace to attach. If 3 arguments are provided (methodName, objOrFunc, funcName), objOrFunc must be the scope to locate the bound function in

funcNameString
Optional.

optional. A string naming the function in objOrFunc to bind to the event. May also be a function reference.

Example 1

add an onclick handler to every button on the page

query("div:nth-child(odd)").connect("onclick", function(e){
    console.log("clicked!");
});
Example 2

attach foo.bar() to every odd div's onmouseover

query("div:nth-child(odd)").connect("onmouseover", foo, "bar");
coords()

Deprecated: Use position() for border-box x/y/w/h or marginBox() for margin-box w/h/l/t. Returns the box objects of all elements in a node list as an Array (not a NodeList). Acts like domGeom.coords, though assumes the node passed is each node in this list.

data(key, value)

stash or get some arbitrary data on/from these nodes.

Stash or get some arbitrary data on/from these nodes. This private _data function is exposed publicly on dojo/NodeList, eg: as the result of a dojo.query call. DIFFERS from jQuery.data in that when used as a getter, the entire list is ALWAYS returned. EVEN WHEN THE LIST IS length == 1.

A single-node version of this function is provided as dojo._nodeData, which follows the same signature, though expects a String ID or DomNode reference in the first position, before key/value arguments.

ParameterTypeDescription
keyObject | String
Optional.

If an object, act as a setter and iterate over said object setting data items as defined. If a string, and value present, set the data for defined key to value If a string, and value absent, act as a getter, returning the data associated with said key

valueAnything
Optional.

The value to set for said key, provided key is a string (and not an object)

Returns: Object | Anything | Nothing

When used as a setter via dojo/NodeList, a NodeList instance is returned for further chaining. When used as a getter via dojo/NodeList an ARRAY of items is returned. The items in the array correspond to the elements in the original list. This is true even when the list length is 1, eg: when looking up a node by ID (#foo)

Example 1

Set a key bar to some data, then retrieve it.

dojo.query(".foo").data("bar", "touched");
var touched = dojo.query(".foo").data("bar");
if(touched[0] == "touched"){ alert('win'); }
Example 2

Get all the data items for a given node.

var list = dojo.query(".foo").data();
var first = list[0];
Example 3

Set the data to a complex hash. Overwrites existing keys with new value

dojo.query(".foo").data({ bar:"baz", foo:"bar" });

Then get some random key:

dojo.query(".foo").data("foo"); // returns [`bar`]
delegate(selector, eventName, fn)

Monitor nodes in this NodeList for [bubbled] events on nodes that match selector. Calls fn(evt) for those events, where (inside of fn()), this == the node that matches the selector.

Sets up event handlers that can catch events on any subnodes matching a given selector, including nodes created after delegate() has been called.

This allows an app to setup a single event handler on a high level node, rather than many event handlers on subnodes. For example, one onclick handler for a Tree widget, rather than separate handlers for each node in the tree. Since setting up many event handlers is expensive, this can increase performance.

Note that delegate() will not work for events that don't bubble, like focus. onmouseenter/onmouseleave also don't currently work.

ParameterTypeDescription
selectorString

CSS selector valid to dojo.query, like ".foo" or "div > span". The selector is relative to the nodes in this NodeList, not the document root. For example myNodeList.delegate("> a", "onclick", ...) will catch events on anchor nodes which are (immediate) children of the nodes in myNodeList.

eventNameString

Standard event name used as an argument to dojo.connect, like "onclick".

fnFunction

Callback function passed the event object, and where this == the node that matches the selector. That means that for example, after setting up a handler via

dojo.query("body").delegate("fieldset", "onclick", ...)

clicking on a fieldset or any nodes inside of a fieldset will be reported

as a click on the fieldset itself.

Returns: undefined
Example
dojo.query("navbar").delegate("a", "onclick", function(evt){
        console.log("user clicked anchor ", this.node);
});
dtl(template, context)

Renders the specified template in each of the NodeList entries.

ParameterTypeDescription
templatedojox/dtl/__StringArgs | String

The template string or location

contextdojox/dtl/__ObjectArgs | Object

The context object or location

Returns: function

Renders the specified template in each of the NodeList entries.

empty()

clears all content from each node in the list. Effectively equivalent to removing all child nodes from every item in the list.

Returns: undefined
end()
Defined by dojo/query

Ends use of the current NodeList by returning the previous NodeList that generated the current NodeList.

Returns the NodeList that generated the current NodeList. If there is no parent NodeList, an empty NodeList is returned.

Returns: undefined | instance
Example
dojo.query("a")
    .filter(".disabled")
        // operate on the anchors that only have a disabled class
        .style("color", "grey")
    .end()
    // jump back to the list of anchors
    .style(...)
even()

Returns the even nodes in this dojo/NodeList as a dojo/NodeList.

.end() can be used on the returned dojo/NodeList to get back to the original dojo/NodeList.

Returns: any | undefined

the even nodes in this dojo/NodeList

Example

assume a DOM created by this markup:

<div class="container">
    <div class="interior red">Red One</div>
    <div class="interior blue">Blue One</div>
    <div class="interior red">Red Two</div>
    <div class="interior blue">Blue Two</div>
</div>

Running this code:

dojo.query(".interior").even();

returns the two divs with class "blue"

every(callback, thisObject)
Defined by dojo/query

see dojo.every() and the Array.every docs. Takes the same structure of arguments and returns as dojo.every() with the caveat that the passed array is implicitly this NodeList

ParameterTypeDescription
callbackFunction

the callback

thisObjectObject
Optional.

the context

Returns: undefined
fadeIn(args)
Defined by dojo/NodeList-fx

fade in all elements of this NodeList via dojo.fadeIn

ParameterTypeDescription
argsObject
Optional.

Additional dojo/_base/fx.Animation arguments to mix into this set with the addition of an auto parameter.

Returns: dojo/_base/fx.Animation | dojo/NodeList | undefined

A special args member auto can be passed to automatically play the animation. If args.auto is present, the original dojo/NodeList will be returned for further chaining. Otherwise the dojo/_base/fx.Animation instance is returned and must be .play()'ed

Example

Fade in all tables with class "blah":

dojo.query("table.blah").fadeIn().play();
fadeOut(args)
Defined by dojo/NodeList-fx

fade out all elements of this NodeList via dojo.fadeOut

ParameterTypeDescription
argsObject
Optional.

Additional dojo/_base/fx.Animation arguments to mix into this set with the addition of an auto parameter.

Returns: dojo/_base/fx.Animation | dojo/NodeList | undefined

A special args member auto can be passed to automatically play the animation. If args.auto is present, the original dojo/NodeList will be returned for further chaining. Otherwise the dojo/_base/fx.Animation instance is returned and must be .play()'ed

Example 1

Fade out all elements with class "zork":

dojo.query(".zork").fadeOut().play();
Example 2

Fade them on a delay and do something at the end:

var fo = dojo.query(".zork").fadeOut();
dojo.connect(fo, "onEnd", function(){ /*...*/ });
fo.play();
Example 3

Using auto:

dojo.query("li").fadeOut({ auto:true }).filter(filterFn).forEach(doit);
filter(filter)

"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.

ParameterTypeDescription
filterString | Function

If a string, a CSS rule like ".thinger" or "div > span".

Returns: undefined
Example 1

"regular" JS filter syntax as exposed in dojo.filter:

dojo.query("*").filter(function(item){
    // highlight every paragraph
    return (item.nodeName == "p");
}).style("backgroundColor", "yellow");
Example 2

the same filtering using a CSS selector

dojo.query("*").filter("p").styles("backgroundColor", "yellow");
first()

Returns the first node in this dojo/NodeList as a dojo/NodeList.

.end() can be used on the returned dojo/NodeList to get back to the original dojo/NodeList.

Returns: any | undefined

the first node in this dojo/NodeList

Example

assume a DOM created by this markup:

<div class="container">
    <div class="red">Red One</div>
    <div class="blue first">Blue One</div>
    <div class="red">Red Two</div>
    <div class="blue last">Blue Two</div>
</div>

Running this code:

dojo.query(".blue").first();

returns the div with class "blue" and "first".

forEach(callback, thisObj)
Defined by dojo/query

see dojo.forEach(). The primary difference is that the acted-on array is implicitly this NodeList. If you want the option to break out of the forEach loop, use every() or some() instead.

ParameterTypeDescription
callbackundefined
thisObjundefined
Returns: function

see dojo.forEach(). The primary difference is that the acted-on array is implicitly this NodeList. If you want the option to break out of the forEach loop, use every() or some() instead.

html(value)

allows setting the innerHTML of each node in the NodeList, if there is a value passed in, otherwise, reads the innerHTML value of the first node.

This method is simpler than the dojo/NodeList.html() method provided by dojo/NodeList-html. This method just does proper innerHTML insertion of HTML fragments, and it allows for the innerHTML to be read for the first node in the node list. Since dojo/NodeList-html already took the "html" name, this method is called "innerHTML". However, if dojo/NodeList-html has not been loaded yet, this module will define an "html" method that can be used instead. Be careful if you are working in an environment where it is possible that dojo/NodeList-html could have been loaded, since its definition of "html" will take precedence. The nodes represented by the value argument will be cloned if more than one node is in this NodeList. The nodes in this NodeList are returned in the "set" usage of this method, not the HTML that was inserted.

ParameterTypeDescription
valueString | DOMNode | NodeList
Optional.
Returns: any | undefined

if no value is passed, the result is String, the innerHTML of the first node. If a value is passed, the return is this dojo/NodeList

Example 1

assume a DOM created by this markup:

<div id="foo"></div>
<div id="bar"></div>

This code inserts <p>Hello World</p> into both divs:

dojo.query("div").innerHTML("<p>Hello World</p>");
Example 2

assume a DOM created by this markup:

<div id="foo"><p>Hello Mars</p></div>
<div id="bar"><p>Hello World</p></div>

This code returns <p>Hello Mars</p>:

var message = dojo.query("div").innerHTML();
indexOf(value, fromIndex)
Defined by dojo/query

see dojo.indexOf(). The primary difference is that the acted-on array is implicitly this NodeList

For more details on the behavior of indexOf, see Mozilla's indexOf docs

ParameterTypeDescription
valueObject

The value to search for.

fromIndexInteger
Optional.

The location to start searching from. Optional. Defaults to 0.

Returns: any | undefined

Positive Integer or 0 for a match, -1 of not found.

innerHTML(value)

allows setting the innerHTML of each node in the NodeList, if there is a value passed in, otherwise, reads the innerHTML value of the first node.

This method is simpler than the dojo/NodeList.html() method provided by dojo/NodeList-html. This method just does proper innerHTML insertion of HTML fragments, and it allows for the innerHTML to be read for the first node in the node list. Since dojo/NodeList-html already took the "html" name, this method is called "innerHTML". However, if dojo/NodeList-html has not been loaded yet, this module will define an "html" method that can be used instead. Be careful if you are working in an environment where it is possible that dojo/NodeList-html could have been loaded, since its definition of "html" will take precedence. The nodes represented by the value argument will be cloned if more than one node is in this NodeList. The nodes in this NodeList are returned in the "set" usage of this method, not the HTML that was inserted.

ParameterTypeDescription
valueString | DOMNode | NodeList
Optional.
Returns: any | undefined

if no value is passed, the result is String, the innerHTML of the first node. If a value is passed, the return is this dojo/NodeList

Example 1

assume a DOM created by this markup:

<div id="foo"></div>
<div id="bar"></div>

This code inserts <p>Hello World</p> into both divs:

dojo.query("div").innerHTML("<p>Hello World</p>");
Example 2

assume a DOM created by this markup:

<div id="foo"><p>Hello Mars</p></div>
<div id="bar"><p>Hello World</p></div>

This code returns <p>Hello Mars</p>:

var message = dojo.query("div").innerHTML();
insertAfter(query)

The nodes in this NodeList will be placed after the nodes matched by the query passed to insertAfter.

The nodes in this NodeList will be cloned if the query matches more than one element. Only the DOM nodes are cloned, not any attached event handlers.

ParameterTypeDescription
queryString
Returns: any | undefined

dojo/NodeList, the nodes currently in this NodeList will be returned, not the matched nodes from the query.

Example

assume a DOM created by this markup:

<span>after</span>
<p>Hello Mars</p>
<p>Hello World</p>

Running this code:

dojo.query("span").insertAfter("p");

Results in this DOM structure:

<p>Hello Mars</p><span>after</span>
<p>Hello World</p><span>after</span>
insertBefore(query)

The nodes in this NodeList will be placed after the nodes matched by the query passed to insertAfter.

The nodes in this NodeList will be cloned if the query matches more than one element. Only the DOM nodes are cloned, not any attached event handlers.

ParameterTypeDescription
queryString
Returns: any | undefined

dojo/NodeList, the nodes currently in this NodeList will be returned, not the matched nodes from the query.

Example

assume a DOM created by this markup:

<span>before</span>
<p>Hello Mars</p>
<p>Hello World</p>

Running this code:

dojo.query("span").insertBefore("p");

Results in this DOM structure:

<span>before</span><p>Hello Mars</p>
<span>before</span><p>Hello World</p>
instantiate(declaredClass, properties)
Defined by dojo/query

Create a new instance of a specified class, using the specified properties and each node in the NodeList as a srcNodeRef.

ParameterTypeDescription
declaredClassString | Object
propertiesObject
Optional.
Returns: undefined
Example

Grabs all buttons in the page and converts them to dijit/form/Button's.

var buttons = query("button").instantiate(Button, {showLabel: true});
last()

Returns the last node in this dojo/NodeList as a dojo/NodeList.

.end() can be used on the returned dojo/NodeList to get back to the original dojo/NodeList.

Returns: any | undefined

the last node in this dojo/NodeList

Example

assume a DOM created by this markup:

<div class="container">
    <div class="red">Red One</div>
    <div class="blue first">Blue One</div>
    <div class="red">Red Two</div>
    <div class="blue last">Blue Two</div>
</div>

Running this code:

dojo.query(".blue").last();

returns the last div with class "blue",

lastIndexOf(value, fromIndex)
Defined by dojo/query

see dojo.lastIndexOf(). The primary difference is that the acted-on array is implicitly this NodeList

For more details on the behavior of lastIndexOf, see Mozilla's lastIndexOf docs

ParameterTypeDescription
valueObject

The value to search for.

fromIndexInteger
Optional.

The location to start searching from. Optional. Defaults to 0.

Returns: any | undefined

Positive Integer or 0 for a match, -1 of not found.

map(func, obj)
Defined by dojo/query

see dojo.map(). The primary difference is that the acted-on array is implicitly this NodeList and the return is a NodeList (a subclass of Array)

ParameterTypeDescription
funcFunction
objFunction
Optional.
Returns: undefined
marginBox()

Returns margin-box size of nodes

next(query)

Returns the next element for nodes in this dojo/NodeList. Optionally takes a query to filter the next elements.

.end() can be used on the returned dojo/NodeList to get back to the original dojo/NodeList.

ParameterTypeDescription
queryString
Optional.

a CSS selector.

Returns: any | undefined

the next element for nodes in this dojo/NodeList.

Example

assume a DOM created by this markup:

<div class="container">
    <div class="red">Red One</div>
    Some Text
    <div class="blue first">Blue One</div>
    <div class="red">Red Two</div>
    <div class="blue last">Blue Two</div>
</div>

Running this code:

dojo.query(".first").next();

returns the div with class "red" and has innerHTML of "Red Two".

Running this code:

dojo.query(".last").next(".red");

does not return any elements.

nextAll(query)

Returns all sibling elements that come after the nodes in this dojo/NodeList. Optionally takes a query to filter the sibling elements.

.end() can be used on the returned dojo/NodeList to get back to the original dojo/NodeList.

ParameterTypeDescription
queryString
Optional.

a CSS selector.

Returns: any | undefined

all sibling elements that come after the nodes in this dojo/NodeList.

Example

assume a DOM created by this markup:

<div class="container">
    <div class="red">Red One</div>
    Some Text
    <div class="blue first">Blue One</div>
    <div class="red next">Red Two</div>
    <div class="blue next">Blue Two</div>
</div>

Running this code:

dojo.query(".first").nextAll();

returns the two divs with class of "next".

Running this code:

dojo.query(".first").nextAll(".red");

returns the one div with class "red" and innerHTML "Red Two".

odd()

Returns the odd nodes in this dojo/NodeList as a dojo/NodeList.

.end() can be used on the returned dojo/NodeList to get back to the original dojo/NodeList.

Returns: any | undefined

the odd nodes in this dojo/NodeList

Example

assume a DOM created by this markup:

<div class="container">
    <div class="interior red">Red One</div>
    <div class="interior blue">Blue One</div>
    <div class="interior red">Red Two</div>
    <div class="interior blue">Blue Two</div>
</div>

Running this code:

dojo.query(".interior").odd();

returns the two divs with class "red"

on(eventName, listener)
Defined by dojo/query

Listen for events on the nodes in the NodeList. Basic usage is:

query(".my-class").on("click", listener);

This supports event delegation by using selectors as the first argument with the event names as

pseudo selectors. For example:

dojo.query("#my-list").on("li:click", listener);

This will listen for click events within <li> elements that are inside the #my-list element.

Because on supports CSS selector syntax, we can use comma-delimited events as well:

dojo.query("#my-list").on("li button:mouseover, li:click", listener);
ParameterTypeDescription
eventNameundefined
listenerundefined
Returns: undefined
orphan(filter)

removes elements in this list that match the filter from their parents and returns them as a new NodeList.

ParameterTypeDescription
filterString
Optional.

CSS selector like ".foo" or "div > span"

Returns: any | undefined

NodeList containing the orphaned elements

parent(query)

Returns immediate parent elements for nodes in this dojo/NodeList. Optionally takes a query to filter the parent elements.

.end() can be used on the returned dojo/NodeList to get back to the original dojo/NodeList.

ParameterTypeDescription
queryString
Optional.

a CSS selector.

Returns: any | undefined

immediate parent elements for nodes in this dojo/NodeList.

Example

assume a DOM created by this markup:

<div class="container">
    <div class="red">Red One</div>
    <div class="blue first"><span class="text">Blue One</span></div>
    <div class="red">Red Two</div>
    <div class="blue"><span class="text">Blue Two</span></div>
</div>

Running this code:

dojo.query(".text").parent();

returns the two divs with class "blue".

Running this code:

dojo.query(".text").parent(".first");

returns the one div with class "blue" and "first".

parents(query)

Returns all parent elements for nodes in this dojo/NodeList. Optionally takes a query to filter the child elements.

.end() can be used on the returned dojo/NodeList to get back to the original dojo/NodeList.

ParameterTypeDescription
queryString
Optional.

a CSS selector.

Returns: any | undefined

all parent elements for nodes in this dojo/NodeList.

Example

assume a DOM created by this markup:

<div class="container">
    <div class="red">Red One</div>
    <div class="blue first"><span class="text">Blue One</span></div>
    <div class="red">Red Two</div>
    <div class="blue"><span class="text">Blue Two</span></div>
</div>

Running this code:

dojo.query(".text").parents();

returns the two divs with class "blue", the div with class "container",

the body element and the html element.

Running this code:

dojo.query(".text").parents(".container");

returns the one div with class "container".

place(queryOrNode, position)

places elements of this node list relative to the first element matched by queryOrNode. Returns the original NodeList. See: dojo.place

ParameterTypeDescription
queryOrNodeString | Node

may be a string representing any valid CSS3 selector or a DOM node. In the selector case, only the first matching element will be used for relative positioning.

positionString

can be one of:

  • "last" (default)
  • "first"
  • "before"
  • "after"
  • "only"
  • "replace"

or an offset in the childNodes property

Returns: undefined
position()

Returns border-box objects (x/y/w/h) of all elements in a node list as an Array (not a NodeList). Acts like dojo.position, though assumes the node passed is each node in this list.

Returns: undefined
prepend(content)

prepends the content to every node in the NodeList.

The content will be cloned if the length of NodeList is greater than 1. Only the DOM nodes are cloned, not any attached event handlers.

ParameterTypeDescription
contentString | DOMNode | NodeList
Returns: any | undefined

dojo/NodeList, the nodes currently in this NodeList will be returned, not the appended content. assume a DOM created by this markup:

<div id="foo"><p>Hello Mars</p></div>
<div id="bar"><p>Hello World</p></div>

Running this code:

dojo.query("div").prepend("<span>prepend</span>");

Results in this DOM structure:

<div id="foo"><span>prepend</span><p>Hello Mars</p></div>
<div id="bar"><span>prepend</span><p>Hello World</p></div>
prependTo(query)

prepends nodes in this NodeList to the nodes matched by the query passed to prependTo.

The nodes in this NodeList will be cloned if the query matches more than one element. Only the DOM nodes are cloned, not any attached event handlers.

ParameterTypeDescription
queryString
Returns: any | undefined

dojo/NodeList, the nodes currently in this NodeList will be returned, not the matched nodes from the query.

Example

assume a DOM created by this markup:

<span>prepend</span>
<p>Hello Mars</p>
<p>Hello World</p>

Running this code:

dojo.query("span").prependTo("p");

Results in this DOM structure:

<p><span>prepend</span>Hello Mars</p>
<p><span>prepend</span>Hello World</p>
prev(query)

Returns the previous element for nodes in this dojo/NodeList. Optionally takes a query to filter the previous elements.

.end() can be used on the returned dojo/NodeList to get back to the original dojo/NodeList.

ParameterTypeDescription
queryString
Optional.

a CSS selector.

Returns: any | undefined

the previous element for nodes in this dojo/NodeList.

Example

assume a DOM created by this markup:

<div class="container">
    <div class="red">Red One</div>
    Some Text
    <div class="blue first">Blue One</div>
    <div class="red">Red Two</div>
    <div class="blue">Blue Two</div>
</div>

Running this code:

dojo.query(".first").prev();

returns the div with class "red" and has innerHTML of "Red One".

Running this code:

dojo.query(".first").prev(".blue");

does not return any elements.

prevAll(query)

Returns all sibling elements that come before the nodes in this dojo/NodeList. Optionally takes a query to filter the sibling elements.

The returned nodes will be in reverse DOM order -- the first node in the list will be the node closest to the original node/NodeList. .end() can be used on the returned dojo/NodeList to get back to the original dojo/NodeList.

ParameterTypeDescription
queryString
Optional.

a CSS selector.

Returns: any | undefined

all sibling elements that come before the nodes in this dojo/NodeList.

Example

assume a DOM created by this markup:

<div class="container">
    <div class="red prev">Red One</div>
    Some Text
    <div class="blue prev">Blue One</div>
    <div class="red second">Red Two</div>
    <div class="blue">Blue Two</div>
</div>

Running this code:

dojo.query(".second").prevAll();

returns the two divs with class of "prev".

Running this code:

dojo.query(".first").prevAll(".red");

returns the one div with class "red prev" and innerHTML "Red One".

query(queryStr)

Returns a new list whose members match the passed query, assuming elements of the current NodeList as the root for each search.

ParameterTypeDescription
queryStrString
Returns: function | undefined

Returns a new list whose members match the passed query, assuming elements of the current NodeList as the root for each search.

Example

assume a DOM created by this markup:

<div id="foo">
    <p>
        bacon is tasty, <span>dontcha think?</span>
    </p>
</div>
<div id="bar">
    <p>great comedians may not be funny <span>in person</span></p>
</div>

If we are presented with the following definition for a NodeList:

var l = new NodeList(dojo.byId("foo"), dojo.byId("bar"));

it's possible to find all span elements under paragraphs

contained by these elements with this sub-query:

var spans = l.query("p span");
remove(filter)

removes elements in this list that match the filter from their parents and returns them as a new NodeList.

ParameterTypeDescription
filterString
Optional.

CSS selector like ".foo" or "div > span"

Returns: any | undefined

NodeList containing the orphaned elements

removeAttr(name)

Removes an attribute from each node in the list.

ParameterTypeDescription
nameString

the name of the attribute to remove

removeClass(className)

removes the specified class from every node in the list

ParameterTypeDescription
classNameString | Array
Optional.

An optional String class name to remove, or several space-separated class names, or an array of class names. If omitted, all class names will be deleted.

Returns: any

this list

removeClassFx(cssClass, args)

Animate the effect of removing a class to all nodes in this list. see dojox.fx.removeClass

ParameterTypeDescription
cssClassundefined
argsundefined
Returns: [object Value(type: function, value: undefined)]
Example
dojo.query(".box").removeClassFx("bar").play();
removeData(key)

Remove the data associated with these nodes.

ParameterTypeDescription
keyString
Optional.

If omitted, clean all data for this node. If passed, remove the data item found at key

replaceAll(query)

replaces nodes matched by the query passed to replaceAll with the nodes in this NodeList.

The nodes in this NodeList will be cloned if the query matches more than one element. Only the DOM nodes are cloned, not any attached event handlers.

ParameterTypeDescription
queryString
Returns: any | function

The nodes currently in this NodeList will be returned, not the matched nodes from the query. The nodes currently in this NodeLIst could have been cloned, so the returned NodeList will include the cloned nodes.

Example

assume a DOM created by this markup:

<div class="container">
    <div class="spacer">___</div>
    <div class="red">Red One</div>
    <div class="spacer">___</div>
    <div class="blue">Blue One</div>
    <div class="spacer">___</div>
    <div class="red">Red Two</div>
    <div class="spacer">___</div>
    <div class="blue">Blue Two</div>
</div>

Running this code:

dojo.query(".red").replaceAll(".blue");

Results in this DOM structure:

<div class="container">
    <div class="spacer">___</div>
    <div class="spacer">___</div>
    <div class="red">Red One</div>
    <div class="red">Red Two</div>
    <div class="spacer">___</div>
    <div class="spacer">___</div>
    <div class="red">Red One</div>
    <div class="red">Red Two</div>
</div>
replaceClass(addClassStr, removeClassStr)

Replaces one or more classes on a node if not present. Operates more quickly than calling removeClass() and addClass()

ParameterTypeDescription
addClassStrString | Array

A String class name to add, or several space-separated class names, or an array of class names.

removeClassStrString | Array
Optional.

A String class name to remove, or several space-separated class names, or an array of class names.

replaceWith(content)

Replaces each node in ths NodeList with the content passed to replaceWith.

The content will be cloned if the length of NodeList is greater than 1. Only the DOM nodes are cloned, not any attached event handlers.

ParameterTypeDescription
contentString | DOMNode | NodeList
Returns: any | function

The nodes currently in this NodeList will be returned, not the replacing content. Note that the returned nodes have been removed from the DOM.

Example

assume a DOM created by this markup:

<div class="container">
    <div class="red">Red One</div>
    <div class="blue">Blue One</div>
    <div class="red">Red Two</div>
    <div class="blue">Blue Two</div>
</div>

Running this code:

dojo.query(".red").replaceWith('<div class="green">Green</div>');

Results in this DOM structure:

<div class="container">
    <div class="green">Green</div>
    <div class="blue">Blue One</div>
    <div class="green">Green</div>
    <div class="blue">Blue Two</div>
</div>
siblings(query)

Returns all sibling elements for nodes in this dojo/NodeList. Optionally takes a query to filter the sibling elements.

.end() can be used on the returned dojo/NodeList to get back to the original dojo/NodeList.

ParameterTypeDescription
queryString
Optional.

a CSS selector.

Returns: any | undefined

all sibling elements for nodes in this dojo/NodeList.

Example

assume a DOM created by this markup:

<div class="container">
    <div class="red">Red One</div>
    Some Text
    <div class="blue first">Blue One</div>
    <div class="red">Red Two</div>
    <div class="blue">Blue Two</div>
</div>

Running this code:

dojo.query(".first").siblings();

returns the two divs with class "red" and the other div

with class "blue" that does not have "first".

Running this code:

dojo.query(".first").siblings(".red");

returns the two div with class "red".

slice(begin, end)
Defined by dojo/query

Returns a new NodeList, maintaining this one in place

This method behaves exactly like the Array.slice method with the caveat that it returns a dojo/NodeList and not a raw Array. For more details, see Mozilla's slice documentation

ParameterTypeDescription
beginInteger

Can be a positive or negative integer, with positive integers noting the offset to begin at, and negative integers denoting an offset from the end (i.e., to the left of the end)

endInteger
Optional.

Optional parameter to describe what position relative to the NodeList's zero index to end the slice at. Like begin, can be positive or negative.

Returns: undefined
slideTo(args)
Defined by dojo/NodeList-fx

slide all elements of the node list to the specified place via dojo/fx.slideTo()

ParameterTypeDescription
argsObject
Optional.

Additional dojo/_base/fx.Animation arguments to mix into this set with the addition of an auto parameter.

Returns: dojo/_base/fx.Animation | dojo/NodeList | undefined

A special args member auto can be passed to automatically play the animation. If args.auto is present, the original dojo/NodeList will be returned for further chaining. Otherwise the dojo/_base/fx.Animation instance is returned and must be .play()'ed

Example
Move all tables with class "blah" to 300/300:
dojo.query("table.blah").slideTo({
    left: 40,
    top: 50
}).play();
some(callback, thisObject)
Defined by dojo/query

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.

ParameterTypeDescription
callbackFunction

the callback

thisObjectObject
Optional.

the context

Returns: undefined
splice(index, howmany, item)
Defined by dojo/query

Returns a new NodeList, manipulating this NodeList based on the arguments passed, potentially splicing in new elements at an offset, optionally deleting elements

This method behaves exactly like the Array.splice method with the caveat that it returns a dojo/NodeList and not a raw Array. For more details, see Mozilla's splice documentation For backwards compatibility, calling .end() on the spliced NodeList does not return the original NodeList -- splice alters the NodeList in place.

ParameterTypeDescription
indexInteger

begin can be a positive or negative integer, with positive integers noting the offset to begin at, and negative integers denoting an offset from the end (i.e., to the left of the end)

howmanyInteger
Optional.

Optional parameter to describe what position relative to the NodeList's zero index to end the slice at. Like begin, can be positive or negative.

itemObject...
Optional.

Any number of optional parameters may be passed in to be spliced into the NodeList

Returns: undefined
style(property, value)

gets or sets the CSS property for every element in the NodeList

ParameterTypeDescription
propertyString

the CSS property to get/set, in JavaScript notation ("lineHieght" instead of "line-height")

valueString
Optional.

optional. The value to set the property to

Returns: any

if no value is passed, the result is an array of strings. If a value is passed, the return is this NodeList

text(value)

allows setting the text value of each node in the NodeList, if there is a value passed in, otherwise, returns the text value for all the nodes in the NodeList in one string.

ParameterTypeDescription
valueString
Returns: any | function | string

if no value is passed, the result is String, the text value of the first node. If a value is passed, the return is this dojo/NodeList

Example 1

assume a DOM created by this markup:

<div id="foo"></div>
<div id="bar"></div>

This code inserts "Hello World" into both divs:

dojo.query("div").text("Hello World");
Example 2

assume a DOM created by this markup:

<div id="foo"><p>Hello Mars <span>today</span></p></div>
<div id="bar"><p>Hello World</p></div>

This code returns "Hello Mars today":

var message = dojo.query("div").text();
toggleClass(className, condition)

Adds a class to node if not present, or removes if present. Pass a boolean condition if you want to explicitly add or remove.

ParameterTypeDescription
classNameString

the CSS class to add

conditionBoolean
Optional.

If passed, true means to add the class, false means to remove.

toggleClassFx(cssClass, force, args)

Animate the effect of adding or removing a class to all nodes in this list. see dojox.fx.toggleClass

ParameterTypeDescription
cssClassundefined
forceundefined
argsundefined
Returns: [object Value(type: function, value: undefined)]
Example
dojo.query(".box").toggleClass("bar").play();
toString()
Defined by dojo/query
Returns: undefined
val(value)

If a value is passed, allows seting the value property of form elements in this NodeList, or properly selecting/checking the right value for radio/checkbox/select elements. If no value is passed, the value of the first node in this NodeList is returned.

ParameterTypeDescription
valueString | Array
Returns: any | function | undefined | null

if no value is passed, the result is String or an Array, for the value of the first node. If a value is passed, the return is this dojo/NodeList

Example

assume a DOM created by this markup:

<input type="text" value="foo">
<select multiple>
    <option value="red" selected>Red</option>
    <option value="blue">Blue</option>
    <option value="yellow" selected>Yellow</option>
</select>

This code gets and sets the values for the form fields above:

dojo.query('[type="text"]').val(); //gets value foo
dojo.query('[type="text"]').val("bar"); //sets the input's value to "bar"
dojo.query("select").val() //gets array value ["red", "yellow"]
dojo.query("select").val(["blue", "yellow"]) //Sets the blue and yellow options to selected.
wipeIn(args)
Defined by dojo/NodeList-fx

wipe in all elements of this NodeList via dojo/fx.wipeIn()

ParameterTypeDescription
argsObject
Optional.

Additional dojo/_base/fx.Animation arguments to mix into this set with the addition of an auto parameter.

Returns: dojo/_base/fx.Animation | dojo/NodeList | undefined

A special args member auto can be passed to automatically play the animation. If args.auto is present, the original dojo/NodeList will be returned for further chaining. Otherwise the dojo/_base/fx.Animation instance is returned and must be .play()'ed

Example 1

Fade in all tables with class "blah":

dojo.query("table.blah").wipeIn().play();
Example 2

Utilizing auto to get the NodeList back:

dojo.query(".titles").wipeIn({ auto:true }).onclick(someFunction);
wipeOut(args)
Defined by dojo/NodeList-fx

wipe out all elements of this NodeList via dojo/fx.wipeOut()

ParameterTypeDescription
argsObject
Optional.

Additional dojo/_base/fx.Animation arguments to mix into this set with the addition of an auto parameter.

Returns: dojo/_base/fx.Animation | dojo/NodeList | undefined

A special args member auto can be passed to automatically play the animation. If args.auto is present, the original dojo/NodeList will be returned for further chaining. Otherwise the dojo/_base/fx.Animation instance is returned and must be .play()'ed

Example

Wipe out all tables with class "blah":

dojo.query("table.blah").wipeOut().play();
wrap(html)

Wrap each node in the NodeList with html passed to wrap.

html will be cloned if the NodeList has more than one element. Only DOM nodes are cloned, not any attached event handlers.

ParameterTypeDescription
htmlString | DOMNode
Returns: any | function

the nodes in the current NodeList will be returned, not the nodes from html argument.

Example

assume a DOM created by this markup:

<b>one</b>
<b>two</b>

Running this code:

dojo.query("b").wrap("<div><span></span></div>");

Results in this DOM structure:

<div><span><b>one</b></span></div>
<div><span><b>two</b></span></div>
wrapAll(html)

Insert html where the first node in this NodeList lives, then place all nodes in this NodeList as the child of the html.

ParameterTypeDescription
htmlString | DOMNode
Returns: any | function

the nodes in the current NodeList will be returned, not the nodes from html argument.

Example

assume a DOM created by this markup:

<div class="container">
    <div class="red">Red One</div>
    <div class="blue">Blue One</div>
    <div class="red">Red Two</div>
    <div class="blue">Blue Two</div>
</div>

Running this code:

dojo.query(".red").wrapAll('<div class="allRed"></div>');

Results in this DOM structure:

<div class="container">
    <div class="allRed">
        <div class="red">Red One</div>
        <div class="red">Red Two</div>
    </div>
    <div class="blue">Blue One</div>
    <div class="blue">Blue Two</div>
</div>
wrapInner(html)

For each node in the NodeList, wrap all its children with the passed in html.

html will be cloned if the NodeList has more than one element. Only DOM nodes are cloned, not any attached event handlers.

ParameterTypeDescription
htmlString | DOMNode
Returns: any | function

the nodes in the current NodeList will be returned, not the nodes from html argument.

Example

assume a DOM created by this markup:

<div class="container">
    <div class="red">Red One</div>
    <div class="blue">Blue One</div>
    <div class="red">Red Two</div>
    <div class="blue">Blue Two</div>
</div>

Running this code:

dojo.query(".red").wrapInner('<span class="special"></span>');

Results in this DOM structure:

<div class="container">
    <div class="red"><span class="special">Red One</span></div>
    <div class="blue">Blue One</div>
    <div class="red"><span class="special">Red Two</span></div>
    <div class="blue">Blue Two</div>
</div>