Mouse Event in TypeScript: Part 1

Introduction
 
A mouse event occurs when a user moves the mouse in the user interface of an application. There are seven types of mouse events, they are:
  1. Onclick
  2. Ondblclick
  3. Onmousedown
  4. Onmouseup
  5. Onmouseover
  6. Onmouseout
  7. Onmousemove
In this article I am describing the "Onclick" and "Ondblclick" mouse event in TypeScript.
 
Onclick

The Onlclick event is the simplest event. The onclick event occurs when the user clicks their mouse on an object on your web page. The onclickevent does not fire for right mouse clicks as well.
 
Note: When using the onclick event to trigger an action, also consider adding this same action to the onkeydown event, to allow the use of that same action by people who don't use a mouse or a touch screen.
 
OndblClick

The OndblClick event occurs when the user double-clicks an element. In another words, it is triggered when the mouse button is pressed and released twice over the same spot. This event is defined by the XHTML specification, but not by the DOM specification.
 
Complete Program
 
Onclick_Ondblclick.ts
  1. class Onclick_Ondblclick  
  2. {  
  3.     Onclick()  
  4.     {  
  5.         alert("Fire Onclick event");  
  6.     }  
  7.     Ondblclick()  
  8.     {  
  9.         alert("Fire Ondblclick event");       
  10.     }  
  11. }  
  12.    
  13. window.onload = () =>  
  14. {  
  15.     var obj = new Onclick_Ondblclick();  
  16.     var bttnclick = <HTMLButtonElement>document.getElementById("onclick");  
  17.     var bttndblclick = <HTMLButtonElement>document.getElementById("ondblclick");  
  18.     bttnclick.onclick = function ()  
  19.     {  
  20.         obj.Onclick();  
  21.     }  
  22.     bttndblclick.ondblclick = function ()  
  23.     {  
  24.         obj.Ondblclick();  
  25.     }  
  26. };  
Onclick_Ondblclick_Event_Demo.html
  1. <!DOCTYPE html>  
  2. <html lang="en" xmlns="http://www.w3.org/1999/xhtml">  
  3. <head>  
  4.     <meta charset="utf-8" />  
  5.     <title>TypeScript HTML App</title>  
  6.     <link rel="stylesheet" href="app.css" type="text/css" />  
  7.     <script src="Onclick_Ondblclick.js"></script>  
  8. </head>  
  9. <body>  
  10.     <h3 style="color: #0033CC">Onclick and Ondblclick event in TypeScript</h3>  
  11.     <div id="content">          
  12.     <input id="onclick" type="button" value="Onclick Event" />  
  13.                      
  14.     <input id="ondblclick" type="button" value="Ondblclick Event" />   
  15.                         </div>  
  16. </body>  
  17. </html>  
Onclick_Ondblclick.js 
  1. var Onclick_Ondblclick = (function () {  
  2.     function Onclick_Ondblclick() { }  
  3.     Onclick_Ondblclick.prototype.Onclick = function () {  
  4.         alert("Fire Onclick event");  
  5.     };  
  6.     Onclick_Ondblclick.prototype.Ondblclick = function () {  
  7.         alert("Fire Ondblclick event");  
  8.     };  
  9.     return Onclick_Ondblclick;  
  10. })();  
  11. window.onload = function () {  
  12.     var obj = new Onclick_Ondblclick();  
  13.     var bttnclick = document.getElementById("onclick");  
  14.     var bttndblclick = document.getElementById("ondblclick");  
  15.     bttnclick.onclick = function () {  
  16.         obj.Onclick();  
  17.     };  
  18.     bttndblclick.ondblclick = function () {  
  19.         obj.Ondblclick();  
  20.     };  
  21. };  
  22. //@ sourceMappingURL=Onclick_Ondblclick.js.map  
Output 1

onclick.jpg
 
Output 2

Double-click on ondblclick button
ondblclick.jpg