Opened 13 years ago

Closed 13 years ago

Last modified 13 years ago

#10143 closed defect (fixed)

dojo.query uses the wrong document

Reported by: arv Owned by: alex
Priority: high Milestone: 1.4
Component: Query Version: 1.4.0b
Keywords: Cc: alex
Blocked By: Blocking:


We are using a port of dojo.query in our js library and I found and fixed some issues. I haven't tested the latest copies of dojo.query so these might have been fixed already.

When using dojo.query on a different document the lookup of the element was done in the wrong document. This might have been an error in our port but I wanted to file the bug to ensure that this is not broken in Dojo.


  <iframe name=ifr></iframe>
  <div id=iframe-test>
    <div id=if1>
      <div class=if2>
        <div id=if3></div>

JS Unit Test:

function testCorrectDocumentInFrame() {
  var frameDocument = window.frames['ifr'].document;
  frameDocument.body.innerHTML =

  var els = dojo.query('#if1 .if2 div', document);
  var frameEls = dojo.query('#if1 .if2 div', frameDocument);

  assertEquals(els.length, frameEls.length);
  assertEquals(1, frameEls.length);

The fix was to get the owner document from the root node inside retFunc inside getElementsFunc:

        retFunc = function(root, arr) {
          var te = GET_OWNER_DOCUMENT(root).getElementById(;
          if (!te || !filterFunc(te)) {
          if (9 == root.nodeType) { // If root's a doc, we just return directly.
            return getArr(te, arr);
          } else { // otherwise check ancestry
            if (_isDescendant(te, root)) {
              return getArr(te, arr);

Change History (3)

comment:1 Changed 13 years ago by alex

Status: newassigned

comment:2 Changed 13 years ago by James Burke

Resolution: fixed
Status: assignedclosed

Thanks for the report. It looks like that particular retFunc is already using ownerDocument:

and there is an iframe test in the dojo.query tests.

comment:3 Changed 13 years ago by bill

Milestone: tbd1.4
Note: See TracTickets for help on using tickets.