Total Page Preview:   000000000381

What is jQuery blur() and focus()?

 jQuery blur() and focus() method

In jQuery, the blur() and focus() methods are used to handle the blur and focus events, respectively, on elements in the DOM (Document Object Model). These events are related to the state of an element gaining or losing focus.

focus() method:
The focus() method is used to attach a function to the focus event of an element. The focus event occurs when an element gains focus, such as when a user clicks inside a form field.
Syntax:
  • selector: A string containing a selector expression.
  • handler: A function to execute when the focus event is triggered.
Example:
In this example, when the user clicks on the input field, the background color changes to light purple.
 
blur() method:
The blur() method is used to attach a function to the blur event of an element. The blur event occurs when an element loses focus, such as when a user clicks outside a form field or tabs away from it.
Syntax:
  • selector: A string containing a selector expression.
  • handler: A function to execute when the blur event is triggered.
Example:
In this example, when the user clicks outside the input field (causing it to lose focus), the background color is reset.
These methods can be useful for enhancing the user experience by providing visual cues or triggering specific actions when elements gain or lose focus.
 
 
 
 
 

Thank You

About Author

Brijesh Kumar

Database Developer

I have more then 6 years Experience in Microsoft Technologies - SQL Server Database, ETL Azure Cloud - Azure SQL Database, CosmosDB, Azure Data Factory, PowerBI, Web Job, Azure Function, Azure Storage, Web Apps, Powershall and Database Migration On-Premise to Azure Cloud.
LinkedIn : https://www.linkedin.com



Comments