Total Page Preview:   000000000368

What is jQuery bind() and unbind() method ?

jQuery bind() and unbind() method

In jQuery, the bind() and unbind() methods were commonly used to attach and detach event handlers to elements. However, as of jQuery version 3.0, these methods have been deprecated in favor of the on() and off() methods. It's recommended to use on() and off() for event handling in the latest versions of jQuery. Nevertheless, I'll provide examples for both bind() and unbind() for educational purposes.

bind() method:
The bind() method is used to attach an event handler function to one or more selected elements. The basic syntax is as follows:
 
  • selector: A string containing a selector expression.
  • event: A string containing one or more JavaScript event types.
  • data: An object containing data that will be passed to the event handler.
  • handler: A function to execute when the event is triggered.
Example:
unbind() method:
The unbind() method is used to remove event handlers that were attached with bind(). The basic syntax is as follows:
  • selector: A string containing a selector expression.
  • event: A string containing one or more JavaScript event types.
  • handler: A reference to the function that should be removed.
Example:
Again, it's recommended to use on() and off() instead of bind() and unbind() in the latest versions of jQuery.
 
 
 
 
 

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