Edit This Code:
<!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() {
    document.getElementById("fname").style.backgroundColor = "red";
}
</script>

</body>
</html>


Result:
Try it Yourself - © w3schools.com
Privacy Policy