Answer the question
In order to leave comments, you need to log in
JS removal error?
Hello, such a problem: there is a function to hide a div block
function deleteAlert() {
var x = document.getElementById("alert");
if (x.style.display === "none") {
x.style.display = "block";
} else {
x.style.display = "none";
}
}
<div class="container mt-5">
@if($errors->any())
@foreach($errors->all() as $error)
<div class="alert alert-danger alert-dismissible fade show" id="alert" role="alert">
{{ $error }}
<button type="button" class="close" data-dismiss="alert" aria-label="Close" onclick="deleteAlert()">
<span aria-hidden="true">×</span>
</button>
</div>
@endforeach
@endif
@if(session('success'))
<div class="alert alert-success alert-dismissible fade show" id="alert" role="alert">
{{ session('success') }}
<button type="button" class="close" data-dismiss="alert" aria-label="Close" onclick="deleteAlert()">
<span aria-hidden="true">×</span>
</button>
</div>
@endif
@yield('content')
</div>
Answer the question
In order to leave comments, you need to log in
<button type="button" class="close" aria-label="Close">...</button>
const alerts = document.querySelectorAll('.alert');
for (const alert of alerts) {
const closeButton = alert.querySelector('.close');
if (closeButton !== null) {
closeButton.addEventListener('click', event => {
event.preventDefault();
alert.style.setProperty('display', 'none');
});
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question