JSFiddle - React, Tailwind, and code Playground

by Norlihazmey Ghazali

HTML

<textarea>Some text</textarea>
<button type="button">Submit</button>

JavaScript

var lastFocus;

$("body").click(function(e) {
    // do whatever you want here
    e.preventDefault();
    e.stopPropagation();
    //$("#results").append("click<br>");
    if (lastFocus) {
        //$("#results").append("setting focus back<br>");
        setTimeout(function() {lastFocus.focus()}, 10);
    }
    return(false);
});
    

$("textarea").blur(function() {
    lastFocus = this;
    //$("#results").append("textarea lost focus<br>");
});