JSFiddle - React, Tailwind, and code Playground
HTML
<script src="https://cdnjs.cloudflare.com/ajax/libs/air-datepicker/2.2.3/js/datepicker.min.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/air-datepicker/2.2.3/css/datepicker.min.css">
<form action="" class="reg__form">
<div class="reg__box">
<input type="checkbox" id="reg__years" class="reg__input">
<label for="reg__years" class="reg__label">мне есть 18 лет.* </label>
<p class="reg__error reg__error--years" style="display: none;">оберите вариант</p>
</div>
<div class="reg__box">
<input type="checkbox" id="reg__agree" class="reg__input">
<label for="reg__agree" class="reg__label">Я соглашаюсь с уловиями.* </label>
<p class="reg__error reg__error--agree" style="display: none;">оберите вариант</p>
</div>
<button class="btn">btn</button>
</form>
CSS
option {
display: block;
padding: 10px;
}
.reg__error {
color: red;
}
JavaScript
function checkCheckBox(elem, error) {
if ($(elem).prop('checked')) {
$(error).css("display", "none");
} else {
$(error).css("display", "block");
}
}
$('.btn').on('click', function() {
checkCheckBox('#reg__agree', '.reg__error--agree');
checkCheckBox('#reg__years', '.reg__error--years');
return false;
});
$('form').on('change', function() {
checkCheckBox('#reg__agree', '.reg__error--agree');
checkCheckBox('#reg__years', '.reg__error--years');
});