<input onfocus="myFunction()"> - Javascript DOM Event

Javascript examples for DOM Event:onfocus

Introduction

The onfocus event occurs when an element gets focus.

Summary

Bubbles No
Cancelable No
Supported HTML tags: ALL HTML elements, EXCEPT: <base>, <bdo>, <br>, <head>, <html>, <iframe>, <meta>, <param>, <script>, <style>, and <title>

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>

<p>This example demonstrates how to assign an "onfocus" event to an input element.</p>

Enter your name: <input type="text" id="fname" onfocus="myFunction()">

<script>
function myFunction() {/* w w w . jav  a 2  s  . c  o  m*/
    document.getElementById("fname").style.backgroundColor = "red";
}
</script>

</body>
</html>

Related Tutorials