To display error message in HTML using JavaScript, do this:
element.textContent = message
.So if this is your HTML element, that holds the message:
<div id="error-message" style="color: red"></div>
Then you can display a message in this element with this JavaScript:
document.getElementById('error-message').textContent = 'Oops! Something went wrong.';