JSFiddle - React, Tailwind, and code Playground
HTML
<div id="chat"></div>
<br><br><br>
Name: <input type="text" id="name"/>
<br><br>
Message: <textarea id="text"></textarea><br>
<input type="button" id="send" value="send"/>
JavaScript
$('#send').click(function() {
var text = $('#text').val(),
name = $('#name').val();
$('#chat').append("<div class='body'>" + name + ": " + text + "</div>");
});
var a, b;
setInterval(function() {
a = $('#chat').text();
}, 900);
setInterval(function() {
b = $('#chat').text();
if (a !== b) {
alert("There has been a new message.");
}
}, 1500);