document.mozSetImageElement(imageElementId, imageElement) tells Firefox which DOM element to use as the live CSS background for a given -moz-element(#id) background ID (MDN). Pass null to clear that override. Returns undefined.
Pass the required arguments shown below. Check return values and browser support before you rely on the result.
Syntax
Call document.mozSetImageElement. Start with this line.
JavaScript
document.mozSetImageElement(id, element)
Call
What it does
document.mozSetImageElement(id, element)
Primary signature.
document.mozSetImageElement(...)
Call with the arguments your case needs.
Built into the browser. Call mozSetImageElement(...) on document — no import required.
Library declarations
JavaScript
document.mozSetImageElement(id, element)
Parameters
Parameter
Description
imageElementId
Required. String ID matching -moz-element(#…)
imageElement
Required. Element to use, or null to remove
Return Value
Return Value
Description
*
undefined
JavaScript Examples
Example 1 — Feature-Detect First
Non-standard APIs must be checked before every call.
JavaScript
if (typeof document.mozSetImageElement === "function") {
console.log("mozSetImageElement available (likely Firefox)");
} else {
console.log("unsupported — use standard CSS backgrounds");
}
Pass null. MDN: removes the background element override.
ID must match. Clear the same string you used when setting.
No return value. The method itself returns undefined; we return a demo label.
Compatibility
Browser Support
Document.mozSetImageElement() is Non-standard on MDN and works in Firefox (4+). Other major engines do not implement it. See the MDN mozSetImageElement() reference.
✓ Non-standard · Firefox
Document.mozSetImageElement()
Firefox-only override for -moz-element() CSS backgrounds. Feature-detect; never require it for product UX.
FirefoxNon-standard
Mozilla Firefox4+
Yes
Google ChromeNot supported
No
Microsoft EdgeNot supported
No
Apple SafariNot supported
No
OperaNot supported
No
Internet ExplorerNot supported
No
mozSetImageElement()Firefox only
Bottom line: Literacy / legacy Firefox demos only. Prefer standard CSS and canvas APIs for real apps.
Frequently Asked Questions
It changes the element used as the CSS background for a background that references a given background element ID via the -moz-element() CSS function (MDN).
MDN marks it Non-standard. It is not part of any specification. It is not marked Deprecated or Experimental on MDN, but you should not depend on it in production.
Firefox only (from Firefox 4+). Chrome, Safari, Edge, Opera, and IE do not support it.
None (undefined) (MDN).
Pass null as imageElement to remove the background element override for that ID (MDN).
Prefer standard CSS backgrounds: url(), gradients, canvas.toDataURL() / drawImage, or SVG patterns. Avoid depending on -moz-element() and mozSetImageElement() for cross-browser apps.