jQuery $.proxy() method
The $.proxy() method takes an existing function and returns a new one that has a specific context. It is generally used to attach events to an element where the context points back to a different object.
We can use the below syntaxes for using the $.proxy() method.
The $.proxy() method accepts some parameters that are defined as follows -
function: It specifies the existing function to be called.
context: It is the object name where function lies.
name: It is the function name whose context is to be changed. It should be a property of the context object.
Now, let's see some of the illustrations of using the $.proxy() method.
In this example, we are using the function and context parameters of the $.proxy() method. Here, the context of the span element will be displayed.Test it Now
After the successful execution, the output will be -
After clicking the text Click me, the output will be -
In this example we are using the context, and name parameters of the $.proxy() method.Test it Now
After clicking the given button, the output will be -