Open In App

HTML DOM blur() Method

The DOM blur method is used to remove the keyboard focus from the current element and also give focus with the help of the focus() method. We can apply the blur to any element and enable it by doing some operations. For example, we can blur to text-box by clicking a button. 

Syntax:



Object.blur()

Example: In this example, we will use the HTML DOM blur() method.




<html>
   
<head>
    <title>HTML DOM blur() Method</title>
</head>
   
<body style="text-align: center;">
    <h1 style="color:green;">
        GeeksforGeeks
    </h1>
    <h2>
        DOM blur Property
    </h2>
    <input type="text" id="txt" placeholder="Enter text here">
    <br>
    <br>
    <button type="button" onclick="inputFocus()">Focus</button>
    <button type="button" onclick="inputBlur()">Blur</button>
 
    <script>
        function inputFocus() {
            document.getElementById('txt').focus();
        }
        function inputBlur() {
            document.getElementById('txt').blur();
        }
    </script>
  </body>
   
</html>

Output: 



 

Supported Browsers: The browser supported by the blur() method are listed below:


Article Tags :