<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>Pointer Lock API</title>
  <script>
    function initiate() {
      const element = document.getElementById("control");
      element.addEventListener("click", lockmouse);
      document.addEventListener("pointerlockchange", checkmouse);
    }
    function lockmouse(event) {
      const element = event.target;
      element.requestPointerLock();
    }
    function checkmouse() {
      console.log("The condition of the mouse changed");
    }
    window.addEventListener("DOMContentLoaded", initiate);
  </script>
</head>
<body>
  <section>
    <p id="control">Click here to lock the mouse</p>
  </section>
</body>
</html>