JSFiddle - React, Tailwind, and code Playground
HTML
<input type="button" value="Click me" onclick="throw_msg()">
<div id="error-box"></div>
CSS
#error-box {
height: 30px;
line-height: 30px;
background: #c00;
text-align: center;
color: #fff;
font-weight: bold;
position: absolute;
bottom: 0;
width: 100%;
}
JavaScript
function throw_msg() {
try {
var a = '';
alert(b);
}
catch(throw_error) {
document.getElementById('error-box').innerHTML=throw_error.message;
setTimeout(
function() {
document.getElementById('error-box').innerHTML='';
}, 2000);
}
}