Show Output
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>Executing a Function on Focus Event in jQuery</title> <script src="https://code.jquery.com/jquery-3.5.1.min.js"></script> <style> label{ display: block; margin: 5px 0; } label span{ display: none; } </style> <script> $(document).ready(function(){ $("input").focus(function(){ $(this).next("span").show().fadeOut("slow"); }); }); </script> </head> <body> <form> <label>Email: <input type="text"> <span>focus fire</span></label> <label>Password: <input type="password"> <span>focus fire</span></label> <label><input type="submit" value="Sign In"> <span>focus fire</span></label> </form> <p><strong>Note:</strong> Click on the form control or press the "Tab" key to set focus.</p> </body> </html>