Repeat button in EJ2 JavaScript Button control

10 May 20236 minutes to read

The Repeat button is a type of Button in that the click event is triggered at regular time interval from the pressed state till the released state.

The following example explains about how to achieve Repeat Button in mouse and touch events.


var button = new ej.buttons.Button({cssClass: `e-small`}, '#button');
var clear = new ej.buttons.Button({cssClass: `e-small`}, '#clear');
var timeout = null;

document.getElementById('clear').onclick = () => {
    document.getElementById('eventlog').innerHTML = '';

document.getElementById('button').addEventListener("mousedown", mouseDownHandler);
document.getElementById('button').addEventListener("mouseup", mouseUpHandler);

function mouseUpHandler(event) {

function mouseDownHandler(event) {
    if (event.which === 1) {
        appendSpanElement('Button click event called<hr>');
        timeout = setInterval(clickEventHandler, 200);
function clickEventHandler() {
    ej.base.EventHandler.trigger(button.element, "click");
    appendSpanElement('Button click event called<hr>');
function appendSpanElement(text) {
    var span = document.createElement('span');
    span.innerHTML = text;
    var log = document.getElementById('eventlog');
    log.insertBefore(span, log.firstChild);
document.getElementById('loader').style.display = "none";
document.getElementById('container').style.visibility = "visible";
<!DOCTYPE html><html lang="en"><head>
    <title>EJ2 Button</title>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="description" content="Typescript UI Controls">
    <meta name="author" content="Syncfusion">
    <link href="" rel="stylesheet">
    <link href="" rel="stylesheet">
    <link href="styles.css" rel="stylesheet">
<script src="" type="text/javascript"></script>
<script src="" type ="text/javascript"></script>

    <div id="container">
        <div class="btncontainer"> 
            <button id="button">Button</button>
        <div class="event" style="height:auto;">
            <table title="Event Trace" style="width:100%">
                <th>Event Trace</th>
                    <div class="eventarea" style="height: 250px;overflow: auto">
                        <span id="eventlog" style="word-break: normal;"></span>
                    <div class="evtbtn" style="padding:20px 0 0 20px">
                        <button id="clear">Clear</button>

var ele = document.getElementById('container');
if(ele) { = "visible";
<script src="index.js" type="text/javascript"></script>
#container {
    visibility: hidden;

#loader {
  color: #008cff;
  height: 40px;
  left: 45%;
  position: absolute;
  top: 45%;
  width: 30%;

.btncontainer {
  float: left;
  width: 40%;

.event {
  float: right;
  width: 60%;
  border-left: 1px solid #D7D7D7;

#eventlog b {
  color: #388e3c;
hr {
   margin: 1px 10px 1px 0px;
   border-top: 1px solid #eee;