Sự kiện onfocus kích hoạt khi phần tử nhận focus (không bubble).
Ví dụ
<!DOCTYPE html>
<html>
<body>
<p>Viết bên dưới:</p>
<input type="text" onfocus="newFunc(this)">
<script>
function newFunc(x) {
x.style.background = "blue";
}
</script>
</body>
</html>