I\'m building a form and I want to use the :invalid
selector to give the \"required\" input fields a red border if the user presses submit without filling them, but
for 'required' validation
way 1 - set 'required' attribute for each element on form submit
// submit button event
$('#form-submit-btn').click(function(event) {
// set required attribute for each element
$('#elm1, #elm2').attr('required','true');
// since required attribute were not set (before this event), prevent form submission
if(!$('#form')[0].checkValidity())
return;
// submit form if form is valid
$('#form').submit();
});
way 2 - use 'data' attribute