Javascript examples for jQuery Selector:focus
The :focus selector selects the element with focus.
The following code shows how to select the element that currently has focus:
<!DOCTYPE html> <html> <head> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script> <script> $(document).ready(function(){ $("input").focus(); $(":focus").css("background-color", "yellow"); });//w w w .java 2s . c om </script> </head> <body> <input type="text" /> <input type="text" /> <input type="text" /> <input type="text" /> <input type="button" text='test' /> </body> </html>