Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

When a input field changes (onchange) I trigger a function to set a variable. The only problem is that the field first has to lose focus before the variable is set and I can check if the field(s) is changed, this is what I want to do when the user clicks on a tab so I can check if the user is forgotten to submit his form in the previous tab. Ho to force lose focus of all possible fields, so first the onchange event can take place?

like image 548
Jilco Tigchelaar Avatar asked May 27 '13 19:05

Jilco Tigchelaar


1 Answers

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(); 
like image 88
Karl-André Gagnon Avatar answered Oct 13 '22 23:10

Karl-André Gagnon