Try clicking the button for a surprise... if you can!

How It Works

function moveButton() { const button = document.getElementById("run"); const container = document.getElementById("button-container");

Getting set up

This function fires the instant your cursor gets close enough to hover over the button - not when you click it. That's the whole trick. First it grabs a reference to the button itself, and to the container it lives inside, since we'll need to know how much room we have to work with.

const oldMiss = document.getElementById("missed"); if (oldMiss) oldMiss.remove(); const buttonX = button.offsetLeft; const buttonY = button.offsetTop; const missMsg = document.createElement("div"); missMsg.id = "missed"; missMsg.className = "missed-message"; missMsg.innerText = "You missed!"; missMsg.style.left = `${buttonX}px`; missMsg.style.top = `${buttonY}px`; container.appendChild(missMsg);

Leaving proof of the near-miss

Before the button moves, it leaves a little "You missed!" note exactly where it used to be - kind of like a taunt. It first checks for and removes any old message so they don't pile up on top of each other, then builds a brand new one from scratch (createElement), styles it, and drops it into the page at the button's last known position.

const maxX = window.innerWidth - button.offsetWidth; const maxY = window.innerHeight - button.offsetHeight; const newX = Math.random() * maxX; const newY = Math.random() * maxY; button.style.left = `${newX}px`; button.style.top = `${newY}px`; }

The actual escape

This figures out the furthest the button could possibly move without falling off the edge of the screen - screen size minus the button's own size - then picks a random spot within that safe zone and teleports the button there. Because this whole function runs on hover, not click, the button is already gone by the time your cursor would have landed on it.

function ohNo() { alert("You got it! 🎉"); }

If you actually catch it

This only runs if someone manages to click the button before it dodges away - which, thanks to the hover trick above, is genuinely hard to pull off on purpose. That's exactly the point.