/

HTML / CSS / JavaScript Tutorial

HTML Event attribute: onfocus

[this page | pdf | back links]

The HTML onfocus attribute specifies the event that is triggered when an element gets focus. It applies to all visible elements.

 

EXAMPLE:


HTML USED IN THIS EXAMPLE:
<!DOCTYPE html>
<html> <!-- Copyright (c) Nematrian Limited 2018 -->
<head></head>
<body>
onfocus: try giving focus to (starting to enter text in) this input field
<input type="text" id="focusinput" onfocus="myOnfocus()"><br>

<script>
function myOnfocus() {document.getElementById("focusinput").style.background="orange";}
</script>

</body>
</html>


NAVIGATION LINKS
Contents | Prev | Next | HTML Attributes


Desktop view | Switch to Mobile