How could I improve next function?
function treatFormLinks () {
if (!$('#One input').valid() ) {
$('#LinkOne').addClass('hasErrors');
}
if (!$('#Two input').valid() ) {
$('#LinkTwo').addClass('hasErrors');
}
if (!$('#Three input').valid() ) {
$('#LinkThree').addClass('hasErrors');
}
};
$("#Submit").click(function () {
treatFormLinks();
});
For example, if I’d had hundred (#One, #Two .etc) containers it would be stupid to create conditions for each case. So how could I make it less “id selector dependent”.
Thank you!
You can try using
eachandtoggleClassmethods.