I tried to make a function to set the left and top offset of an HTML element. here is the code I tried:
window.addEventListener("mousemove", (e) => {
let x = e.clientX;
let y = e.clientY;
setLeft("demo", x);
setTop("demo", y);
});
function setLeft(id, left) {
document.getElementById(id).style.left = left;
}
function setTop(id, top) {
document.getElementById(id).style.top = top;
}
the "demo" element is set to position:absolute. code gives no error, but does not work. Why?