JSFiddle - React, Tailwind, and code Playground

by Mohammed Sameer

HTML

<textarea id="myElement">
  hi
</textarea>

JavaScript

var timeoutId = 0;

$('#myElement').mousedown(function() {
  timeoutId = setTimeout(myFunction, 1000);
}).bind('mouseup mouseleave', function() {
  clearTimeout(timeoutId);
  
  $('#myElement').prop('readonly', false);
  $('#myElement').css('background','#fff');
});

function myFunction() {
  $('#myElement').prop('readonly', true);
  $('#myElement').css('background','red');
}