Using "onfocus" together with the "onblur" event: - Javascript DOM Event

Javascript examples for DOM Event:onfocus

Description

Using "onfocus" together with the "onblur" event:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>

Enter your name: <input type="text" id="myInput" onfocus="focusFunction()" onblur="blurFunction()">

<script>
function focusFunction() {/*w  ww.  ja  va2s  .  c o  m*/
    document.getElementById("myInput").style.background = "yellow";
}

function blurFunction() {
    document.getElementById("myInput").style.background = "red";
}
</script>

</body>
</html>

Related Tutorials