Find out the Events Type

Description

The type property tells you which kind of event you are dealing with. This value is provided as a string, such as mouseover.

Example


<!DOCTYPE HTML>
<html>
<head>
<style type="text/css">
p {<!-- www.j av a 2s .c  o  m-->
  background: gray;
  color: white;
}
</style>
</head>
<body>
  <p>This is a test. 
  </p>
  <p id="block2">This is a test. 
  </p>
  <script type="text/javascript">
    var pElems = document.getElementsByTagName("p");
    for ( var i = 0; i < pElems.length; i++) {
      pElems[i].onmouseover = handleMouseEvent;
      pElems[i].onmouseout = handleMouseEvent;
    }
    function handleMouseEvent(e) {
      if (e.type == "mouseover") {
          e.target.innerHTML += "mouseover";
        e.target.style.background = 'white';
        e.target.style.color = 'black';
      } else {
        e.target.style.removeProperty('color');
        e.target.style.removeProperty('background');
      }
    }
  </script>
</body>
</html>

Click to view the demo





















Home »
  Javascript »
    Javascript Reference »




Array
Canvas Context
CSSStyleDeclaration
CSSStyleSheet
Date
Document
Event
Global
History
HTMLElement
Input Element
Location
Math
Number
String
Window