In the HTMLInputElement interface, there is no such property as valid or invalid.
You can use the setCustomValidity(error) method with native form validation.
As for your script, here’s a demo that should work in all HTML5 compliant browsers:
$('input[name=pass2]').keyup(function () {
'use strict';
if ($('input[name=pass]').val() === $(this).val()) {
$('#pass_hint').html('match');
this.setCustomValidity('');
} else {
$('#pass_hint').html('mismatch');
this.setCustomValidity('Passwords must match');
}
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<form action='#'>
<p>Password:
<input name=pass type=password required>
</p>
<p>Verify:
<input name=pass2 type=password required>
</p>
<p id=pass_hint></p>
<button type=submit>Submit</button>
</form>