जब तत्व फोकस हो जाता है तो ऑनफोकस ईवेंट चालू हो जाता है। ऑनफोकस . को लागू करने का तरीका जानने के लिए आप निम्न कोड को चलाने का प्रयास कर सकते हैं जावास्क्रिप्ट में घटना।
उदाहरण
<!DOCTYPE html>
<html>
<body>
<p>Write below:</p>
<input type = "text" onfocus = "newFunc(this)">
<script>
function newFunc(x) {
x.style.background = "blue";
}
</script>
</body>
</html>