I'm Working on a small project using jQuery and I'm doing form validation, I would like to know if is there any solution to avoid repeaters in my code, talking about (addClass and removeClass)
my code :
if (value.string.match(regex)) {
$('#' + index).removeClass('is-invalid')
$('#' + index).addClass('is-valid')
} else {
$('#' + index).removeClass('is-valid')
$('#' + index).addClass('is-invalid')
}
question from:https://stackoverflow.com/questions/66055800/is-there-any-way-toggleclass-without-rewriting-the-same-code