Tried everything else with no luck: To add a validity test to all text input elements: Let me share an example which I developed with BS4, thymeleaf and Spring boot. Combine the focus event with the change event to achieve what you want: Working example: http://jsfiddle.net/x5PKf/766, please don't use a global var for this - store the prev value at the data You should be using querySelector to achieve this. ;-), @OZZIE - Look at the assignment statement beginning with. What is the purpose of this D-shaped ring at the base of the tongue on my hiking boots? If you ever run across code written purely for InternetExplorer you might see this: Running the above in Firefox et al will give you an 'is not a function' error, because InternetExplorer allows you to get away with using () instead of []: The correct way is to use square brackets. Can I use a vintage derailleur adapter claw on a modern derailleur, Is Hahn-Banach equivalent to the ultrafilter lemma in ZF, Parent based Selectable Entries Condition. This is the most general and comprehensive solution here. In some rare instances you may need to use parentheses, but this would be very rare. While using W3Schools, you agree to have read and accepted our, , , , , , , , , , , , , , , , , ,