if (!var) {
return document.getElementById('error-alert').style.display = 'block';
}
<div id="alerts">
<div id="error-alert" class="alert alert-danger alert-dismissible fade show" role="alert" style="display: none;">
<button type="button" class="close" data-dismiss="alert">×</button>
<strong>Ошибка!</strong>
</div>
</div>