Javascript DOM onfocusin Event via addEventListener() method

Introduction

In JavaScript, using the addEventListener() method:

This example uses the addEventListener() method to attach a "focusin" event to an input element.

object.addEventListener("focusin",
       myScript);

View in separate window

<!DOCTYPE html>
<html>
<body>
Enter your name: <input type="text" id="fname">

<script>
document.getElementById("fname").addEventListener("focusin", myFunction);

function myFunction() {//from  w w  w. java2 s  .  com
  document.getElementById("fname").style.backgroundColor = "red";
}
</script>

</body>
</html>
Bubbles:
Cancelable:
Event type:
Supported HTML tags:











Yes
No
FocusEvent
ALL HTML elements, EXCEPT:
<base>,
<bdo>,
<br>,
<head>,
<html>,
<iframe>,
<meta>,
<param>,
<script>,
<style>, and
<title>



PreviousNext

Related