HTML DOM Event type Property

HTMLWeb DevelopmentFront End Technology

The HTML DOM Event type property returns a string corresponding to the event’s type such as click, keypress, load, or touchend.

Following is the syntax −

Returning number of seconds a transition has run −

event.type

Let us see an example of Event type property −

Example

 Live Demo

<!DOCTYPE html>
<html>
<head>
<title>HTML DOM Event type</title>
<style>
   form {
      width:70%;
      margin: 0 auto;
      text-align: center;
   }
   * {
      padding: 2px;
      margin:5px;
   }
   input[type="button"] {
      border-radius: 10px;
   }
   .playArea {
      display: inline-block;
      border-radius: 50%;
      background-color: #DC3545;
      width: 50px;
      height: 50px;
      border: 3px solid #AC3509;
      transition: all 1.3s ease;
   }
   .clickStyle {
      transform: scale(1.5);
   }
   .touchstartStyle {
      transform: translateX(50px);
   }
</style>
</head>
<body>
   <form>
      <fieldset>
         <legend>HTML-DOM-Event-type</legend>
         <div class="playArea"></div><br>
         <div id="divDisplay"></div>
      </fieldset>
   </form>
<script>
   var divDisplay = document.getElementById("divDisplay");
   var playDisplay = document.getElementsByClassName("playArea")[0];
   var TranslateXSelect = document.getElementById("TranslateXSelect");
   var ScaleSelect = document.getElementById("ScaleSelect");
   function getEventType(event) {
      if(event.type === 'click'){
         playDisplay.classList.remove('touchstartStyle');
         playDisplay.classList.add('clickStyle');
            divDisplay.textContent = 'Event Fired: '+event.type;
      } else if(event.type === 'touchstart'){
         playDisplay.classList.remove('clickStyle');
         playDisplay.classList.add('touchstartStyle');
         divDisplay.textContent = 'Event Fired: '+event.type;
      }
   }
   playDisplay.addEventListener("click", getEventType);
   playDisplay.addEventListener("touchstart", getEventType);
</script>
</body>
</html>

Output

Before clicking the div element −

After clicking the div element −

After touching the div element −

raja
Published on 30-Oct-2019 10:40:14
Advertisements