How to force to lose focus of all fields in a form in jQuery

Solution 1:

You can use this :

$(':focus').blur()

If you don't have jQuery in your site, you can replace it by :

let el = document.querySelector( ':focus' );
if( el ) el.blur();

Solution 2:

You don't need jQuery for this; vanillaJS can do this, too.

document.activeElement.blur();

Note: Usually, I would check for null-ness before calling a method, but activeElement will only ever return null if there is no ‹body› node, so this direct call is pretty safe.