Get to know MDN better
This feature is not Baseline because it does not work in some of the most widely-used browsers.
The pointerLockElement read-only property of the Document interface provides the element set as the target for mouse events while the pointer is locked. It is null if lock is pending, pointer is unlocked, or the target is in another document.
An Element or null.
This example contains a <div> element that in turn contains a <button>. Clicking the button requests pointer lock for the <div>.
The example also listens for the pointerlockchange event: when this event is fired, the event handler disables the "Lock" button if an element in the document has the pointer lock, and enables the button otherwise.
The effect of this is that if you click the "Lock" button, the pointer is locked and the button is disabled: if you then exit pointer lock (for example, by pressing the Escape key), the button is enabled again.
| Pointer Lock 2.0 # dom-documentorshadowroot-pointerlockelement |
Enable JavaScript to view this browser compatibility table.
This page was last modified on Dec 11, 2023 by MDN contributors.
Your blueprint for a better internet.
Visit Mozilla Corporation’s not-for-profit parent, the Mozilla Foundation.
Portions of this content are ©1998–2026 by individual mozilla.org contributors. Content available under a Creative Commons license.