Why focusout (); in jQuery not execute function after focusing from field?

I am trying to use the focusout function ( http://api.jquery.com/focusout/ ) in jQuery to execute the function after the user is distracted from the input form field, but it does not work.

Here is my code:

$("#employee_id").focusout(function(){ var employeeId = $("#employee_id").val(); if(employeeId == '') { $("#employee_id").after('<div class="error">Your employee id number is required.</div>'); hasError = true; } }); 

I am using jquery-1.3.2.min.js since the other plugin I am using (qtip) gives me an error when I try to use jquery-1.4.2.min.js.

How can I make a focus event, or is there another way to do what I'm trying to accomplish?

+4
source share
1 answer

Since you just care about this field, not the parent / bubble, use .blur() :

 $("#employee_id").blur(function(){ if($(this).val() == '') { $(this).after('<div class="error">Your employee id number is required.</div>'); hasError = true; } }); 
+9
source

Source: https://habr.com/ru/post/1302980/


All Articles