JSFiddle - React, Tailwind, and code Playground

HTML

<input type="text" id="foobar">

JavaScript

$(function()
{
    $(':text').each(function()
    {
        var text = $(this);
        text.keyup(function(event)
        {
            if (event.which == 27)
                reset_textbox();
        });
        
        reset_textbox();
        
        function reset_textbox()
        {
                text.val(text.attr('id'));            
        }
    });
});