- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
jQuery :focus Selector
The :focus selector in jQuery is used to select the element which currently has focus.
Syntax
The syntax is as follows −
$(":focus")
Example
Let us now see an example to implement the :focus() selector −
<!DOCTYPE html> <html> <head> <style> .one { color: brown; background-color: orange; font-size: 16px; border: 2px blue solid; } </style> <script src="https://code.jquery.com/jquery-3.4.1.js"></script> <script> $(document).ready(function(){ $("input").focus(); $(":focus").addClass("one"); }); </script> </head> <h2>Fill the form</h2> <body> ID: <input type="text" name="id"><br> Rank: <input type="text" name="rank"><br> Fav. Subjects: Maths: <input type="checkbox" name="sub" value="maths"> English <input type="checkbox" name="sub" value="english"><br> <input type="submit" value="Submit"><br> </body> </html>
Output
This will produce the following output −
- Related Articles
- Role of CSS :focus Selector
- jQuery :button Selector
- jQuery :checkbox Selector
- jQuery :checked Selector
- jQuery :contains() Selector
- jQuery :disabled Selector
- jQuery :empty Selector
- jQuery :enabled Selector
- jQuery :even Selector
- jQuery :file Selector
- jQuery :first Selector
- jQuery :gt() Selector
- jQuery :header Selector
- jQuery :hidden Selector
- jQuery :image Selector

Advertisements