querySelector() and getElementsByClassName return the wrong value after changing the class of a node in browser.xul

RESOLVED INVALID

Status

()

Core
DOM
RESOLVED INVALID
6 years ago
6 years ago

People

(Reporter: paul, Unassigned)

Tracking

Firefox Tracking Flags

(Not tracked)

Details

(Reporter)

Description

6 years ago
STR:
- open the devtools window (the web console for example)
- start the scratchpad (browser environment)
- execute this code:

let iframe = document.getElementById("devtools-toolbox-bottom-iframe");

let CLASS_NAME = "foobar";
iframe.className = CLASS_NAME;
iframe.setAttribute("class", CLASS_NAME); // trying both ways

alert("why is this null: " + document.querySelector("." + CLASS_NAME));
alert("... and this is true: " + iframe.mozMatchesSelector("." + CLASS_NAME));
alert("... and this undefined: " + document.getElementsByClassName(CLASS_NAME)[0]);

- expected result: XULNode / true / XULNode
- actual result: null / true / undefined
(Reporter)

Comment 1

6 years ago
It appears to be specific to the devtools-toolbox-bottom-iframe, that is created here: http://mxr.mozilla.org/mozilla-central/source/browser/devtools/framework/ToolboxHosts.jsm#56
(Reporter)

Comment 2

6 years ago
I think this is actually an expected behavior because the iframe is an anonymous node.
(Reporter)

Updated

6 years ago
Status: NEW → RESOLVED
Last Resolved: 6 years ago
Resolution: --- → INVALID
Yes, exactly.  getElementById on XUL document is a glaring spec violation in that it returns anonymous things, unfortunately; I tried to fix that at one point but ran into all sorts of chrome code relying on the behavior.  :(
You need to log in before you can comment on or make changes to this bug.