Try It Editor
Tip: Press
Ctrl/⌘ + Enter
to Run
▶ Run
Reset
Copy
Download
Code
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>focus()/blur()</title> <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script> <style>#t{border:1px solid #ccc;padding:6px;}</style> </head> <body> <input id="t" placeholder="Focus me"> <div id="msg"></div> <script> $("#t").on("focus", function(){ $(this).css("border-color","#4caf50"); $("#msg").text("focused"); }); $("#t").on("blur", function(){ $(this).css("border-color","#ccc"); $("#msg").text("blurred"); }); </script> </body> </html>
Output