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 focus() method. We can apply the blur to any element and enable it by doing some operation. For example, we can blur to text-box by clicking a button.

Syntax:

Object.blur()

Example:

filter_none

edit
close

play_arrow

link
brightness_4
code

<html>
  
<head>
    <title>HTML DOM blur Property</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>

chevron_right


Output:
After clicking on focus button:
blur

After clicking on blur button:
blur

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

  • Google Chrome
  • Internet Explorer
  • Firefox
  • Opera
  • Safari


My Personal Notes arrow_drop_up


If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.




Article Tags :
Practice Tags :


Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.