/

HTML / CSS / JavaScript Tutorial

HTML Event attribute: onfocusin

[this page | pdf | back links]

The HTML onfocusin attribute specifies the event that is triggered when an element is about to get focus. It is similar to the onfocus attribute except that it also ‘bubbles’.

 

EXAMPLE:


HTML USED IN THIS EXAMPLE:
<!DOCTYPE html>
<html> <!-- Copyright (c) Nematrian Limited 2018 -->
<head></head>
<body>
onfocusin, onfocusout: try giving focus to (starting to enter text in) and away from (clicking outside) this input field 
<input type="text" id="focusinput" onfocusin="myOnfocusin()" onfocusout="myOnfocusout()"><br>

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

</body>
</html>


NAVIGATION LINKS
Contents | Prev | Next | HTML Attributes


Desktop view | Switch to Mobile