I used the .css() for changing the border color for an element, and every time I perform the action that trigger the jQuery script, the border changes like it supposed to, but changes back after a second.
This is the code:
$("#form1").submit(function() {
if (!$('#foo').val().length) {
$("#foo").css('border', '3px solid red');
}
$("#foo").css('border', '3px solid red');
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.2/jquery.min.js"></script>
<div>
<form id="form1" name="form1" method="post">
<div class="textInput">
PO: <input type="text" class="txtBox" name="foo" id="foo"><br /><br />
</div>
<input type="submit" name="Submit" value="Submit" />
</form>
</div>
No additional JS or css file.
.submit(function(e) { e.preventDefault(); /* the rest */ }. You can also submit it manually after some operations if you prevented the submit this way