<div id="container">
<button id="lock">Lock</button>
</div>Document: pointerLockElement property / notebook
Document: pointerLockElement property
Runnable notebook: every JavaScript, HTML and CSS example on this page executes in a sandboxed local frame. Nothing leaves the browser.
div {
height: 100px;
width: 200px;
border: 2px solid blue;
}const lock = document.querySelector("#lock");
const container = document.querySelector("#container");
lock.addEventListener("click", () => {
container.requestPointerLock();
});
document.addEventListener("pointerlockchange", () => {
const locked = document.pointerLockElement;
lock.disabled = Boolean(locked);
});