jQuery <input> handle focus lost event and check value
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>Check If Input Text Box has Empty Value in jQuery</title> <style> .error{/*from w w w .jav a 2s. com*/ outline: 1px solid red; } </style> <script src="https://code.jquery.com/jquery-1.12.4.min.js"></script> <script> $(document).ready(function(){ $('#myForm input[type="text"]').blur(function(){ if(!$(this).val()){ $(this).addClass("error"); } else{ $(this).removeClass("error"); } }); }); </script> </head> <body> <form id="myForm"> <p><label>First Name: <input type="text"></label></p> <p><label>Last Name: <input type="text"></label></p> <p><label>Email Address: <input type="text"></label></p> </form> </body> </html>