Saturday, March 29, 2014

Some very useful Dojo functions

Just another post on Dojo. Nothing special, just for self-reference.


dojo.query() returns a list of DOM nodes based on a CSS selector.

dojo/query is the AMD module containing the query function in 1.7


Since the JavaScript forEach() function is not supported natively on every browser, dojo.forEach provides the standard JavaScript 1.6 forEach construct everywhere. dojo.forEach lets you apply a function to each element of an array, emulating a for loop.

dojo.forEach() cannot terminate a loop (except when throwing an exception). Use dojo.some() or dojo.every() instead.

The dojo.query and dojo.forEach example below retrieves the input elements of type "checkbox" within a node with id="sidebar". It then iterates thru the list and changes the input element's 'disabled' property.

	var checkboxes = dojo.query("#sidebar input[type=checkbox]");
	dojo.forEach(checkboxes,function(checkbox) {
		checkbox.disabled = !checkbox.disabled;


Returns an array of all non-nested widgets inside the given DOM node.

var cpDivContainers = dijit.findWidgets(dojo.byId('divContainer'));
dojo.forEach(cpDivContainers, function(cp) {
	//destroy the widget (remove from the registry)

Another example:

dojo.forEach(dijit.findWidgets(dojo.byId('divContainer')), function(w) {

No comments:

Post a Comment