Element blur() Method - Javascript DOM

Javascript examples for DOM:Element blur

Description

The blur() method removes focus from an element.

Parameters

None

Return Value:

No return value

The following code shows how to Remove focus from an <a> element:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<head>
<style>
a:focus, a:active {
    color: green;
}
</style>//from   ww w  .jav  a  2s.  co  m
</head>
<body>

<a id="myAnchor" href="http://www.java2s.com">check out java2s.com</a>

<input type="button" onclick="getfocus()" value="Get focus">
<input type="button" onclick="losefocus()" value="Lose focus">

<script>
function getfocus() {
    document.getElementById("myAnchor").focus();
}

function losefocus() {
    document.getElementById("myAnchor").blur();
}
</script>

</body>
</html>

Related Tutorials