JSFiddle - React, Tailwind, and code Playground

by blineberry

HTML

<button class="start">Start Timer</button>
<button class="stop" disabled>Stop Timer</button>

JavaScript

// Higher-scoped variables
var start;
var timeSpent;

// Bind to the start timer click event
$('.start').click(function() {
    start = new Date().getTime();
    
    $(this).attr('disabled', 'disabled');
    $('.stop').removeAttr('disabled');
});
// Bind to the stop timer click event
$('.stop').click(function() {
    var end = new Date().getTime();
    timeSpent = end - start;   
    
    $(this).attr('disabled', 'disabled');
    $('.start').removeAttr('disabled');
    
    // Whatever action we want to do with our information
    alert(timeSpent + 'ms');    
});