Javascript DOM onfocusin Event

Introduction

Execute a JavaScript when an input field is about to get focus:

When the input field gets focus, a function is triggered which changes the background-color.

View in separate window

<!DOCTYPE html>
<html>
<body>
Enter your name: <input type="text" onfocusin="myFunction(this)">
<script>
function myFunction(x) {//  w  w  w  . j ava2 s. co  m
  x.style.background = "yellow";
}
</script>

</body>
</html>

The onfocusin event occurs when an element is about to get focus.

The onfocusin event is similar to the onfocus event.

The onfocus event does not bubble.

To find out whether an element or its child gets the focus, you should use the onfocusin event.

The onfocusin event is the opposite of the onfocusout event.

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