i2tutorials

Javascript Blur

Javascript Blur

 

The focus field can be removed with the help of the blur() method in javascript.

 

Syntax:

 

HTMLElementObject.blur()

 

Parameters: This method does not accept any parameter.

 

EXAMPLE:

 

<html>

<head> 
      <script type="text/javascript"> 
              function setFocus() { 
                      document.getElementById("focus").focus(); 
              }

              function removeFocus() { 
                      document.getElementById("focus").blur(); 
              } 
      </script> 
</head>

<body> 
      <input type="button" onclick="setFocus()" value="set focus"> 
      <input type="button" onclick="removeFocus()" value="remove focus"> 
      <br> 
      <br> 
      <input type="text" id="focus"> 
</body>

</html>

 

OUTPUT:

 

Javascript Blur

 

Exit mobile version