Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width">
  <title>JS Bin</title>
</head>
<body>
  <!-- Input tag -->
  <input id="myInput" type="text" placeholder="Enter some text here" />
  <!-- Button -->
  <button id="myBtn">Click to remove focus from input</button>
</body>
</html>
 
// first get a reference
// to the input tag and button
const input = document.querySelector("#myInput");
const button = document.querySelector("#myBtn");
// use the focus method
// to focus input input tag
// when user visits
input.focus();
// attach a click handler
// to button element
button.addEventListener("click", () => {
  // whene the user click the button
  // remove the focus form the input tag
  // We can use the blur() method on the
  // input element to acheive that
  input.blur();
});
Output

This bin was created anonymously and its free preview time has expired (learn why). — Get a free unrestricted account

Dismiss x
public
Bin info
anonymouspro
0viewers