Reputation: 584
From my testing, it appears that dojo's query()
function only selects from among elements that are part of a page's DOM.
For example, suppose I have a node named rootNode
that has some number of descendents with the class someClass
. This code:
var nodeList = query(".someclass", rootNode);
will return an empty NodeList if rootNode
has been removed from the DOM (but, of course, if rootNode
is part of the DOM, it will return all the nodes with class someClass
.
My question: is there a way to use query()
in this situation? If not, what is the preferred way for handling this? It looks to me like some of NodeList's methods can be used with a filter(remove and place), but that's not quite the same.
Upvotes: 1
Views: 86
Reputation: 584
My answer turned out to be very simple: although I didn't find it in the documentation, you can simply call query()
on a NodeList. e.g.
var nodeList = query.NodeList();
nodeList.push(rootNode);
var results = nodeList.query(yourSelector);
Note, however: if yourSelector
is a unique id and rootNode
has been removed from the DOM, it doesn't appear to work. Other types of selectors (class, children, etc) seem to work. I wonder if that's a bug in Dojo...
Upvotes: 1
Reputation: 25089
You can get a dojo NodeList
as the return result of your dojo.query
. Then you can use nodes.map
or nodes.every
to find the elements you want.
http://dojotoolkit.org/reference-guide/1.9/dojo/NodeList.html
Upvotes: 1