JSFiddle - React, Tailwind, and code Playground

HTML

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

JavaScript

$("#myDiv").keyup(function() {

    var val = $("#myDiv").val(),
        len = val.length - 1;

    if (val[len] == ' ') {
        alert("space found");
    }

});