Advertisement
Home Open Editor ❯

HTML onblur Attribute

Example

<input type="text" name="fname" id="fname" onblur="myFunction()">

<p id="demo"></p>

<script>
function myFunction() {
  var x = document.getElementById("fname");
  document.getElementById("demo").innerHTML = x.value;
}
</script>

Try this code ❯

Meaning

The onblur attribute occurs when an element loses focus, meaning that the user has moved focus to another element, typically either by clicking the mouse or by tabbing.


Standard Syntax

<element onblur="script">


Applies to:

The onblur attribute can be used on the following element:

Element Attribute
All HTML elements onblur

Advertisement

Attribute Values

Value Description
script Specifies the script to be run on onblur.
Home Open Editor ❯
Advertisement