I encountered an issue with the alert in my html
code:
<div class="alert alert-success alert-dismissible fade show d-flex align-items-center justify-content-center" id="alert" style="display:none;">
<button type="button" class="btn-close" data-bs-dismiss="alert"></button>
<span id="msg">Success</span>
</div>
The intention was to have the alert hidden initially and then display a danger
alert upon clicking the submit button in my script using this piece of js
:
document.getElementById("submit").addEventListener("click",function(){
document.getElementById("alert").className="alert alert-danger alert-dismissible fade show d-flex align-items-center justify-content-center";
document.getElementById("msg").innerHTML="Danger";
document.getElementById("alert").style.display="block";
})
However, when running the code, the alert remains visible from the start. Additionally, upon clicking the submit button, I encounter the following error message:
Uncaught TypeError: Cannot set properties of null (setting 'className')
I am seeking assistance in understanding why this is happening. Any help would be greatly appreciated.