ใช้ โฟกัส คุณลักษณะเพื่อรันสคริปต์เมื่อองค์ประกอบได้รับการโฟกัสใน HTML
ตัวอย่าง
คุณสามารถลองเรียกใช้โค้ดต่อไปนี้เพื่อใช้งาน onfocus แอตทริบิวต์ −
<!DOCTYPE html>
<html>
<body>
<p>Enter subject name below,</p>
Subject: <input type = "text" id = "sname" onfocus = "display(this.id)">
<br>
<script>
function display(val) {
document.getElementById(val).style.background = "blue";
}
</script>
</body>
</html>