#my-box {
background-image: -moz-element(#canvas-bg);
text-align: center;
width: 400px;
height: 400px;
cursor: pointer;
}Document: mozSetImageElement() method / notebook
Document: mozSetImageElement() method
Runnable notebook: every JavaScript, HTML and CSS example on this page executes in a sandboxed local frame. Nothing leaves the browser.
let c = 0x00;
function clicked() {
const canvas = document.createElement("canvas");
canvas.setAttribute("width", 100);
canvas.setAttribute("height", 100);
const ctx = canvas.getContext("2d");
ctx.fillStyle = `#${c.toString(16)}0000`;
ctx.fillRect(25, 25, 75, 75);
c += 0x11;
if (c > 0xff) {
c = 0x00;
}
document.mozSetImageElement("canvas-bg", canvas);
}