![]() |
Definition and UsageThe onfocus attribute fires the moment that the element gets focus. Onfocus is most often used with <input>, <select>, and <a>. Tip: The onfocus attribute is the opposite of the onblur attribute. Applies toThe onfocus attribute is part of the Event Attributes, and can be used on any HTML elements.
Browser Support |
Example:
HTML
First name: <input type="text" id="fname" onfocus="myFunction(this.id)"><br>
Last name: <input type="text" id="lname" onfocus="myFunction(this.id)">
<script>
function myFunction(x) {
document.getElementById(x).style.background = "yellow";
}
</script>
html onfocus attribute |
How to Execute a JavaScript when an input field gets focus | HTML Attribute |
Read Full: | HTML Attribute |
Type: | Develop |
Category: | Web Tutorial |
Sub Category: | HTML Attribute |
Uploaded by: | Admin |
Views: | 127 |
Reffered: https://www.w3schools.com/tags/att_onfocus.asp