Home >>jQuery Tutorial >jQuery $.proxy() Method

jQuery $.proxy() Method

jQuery $.proxy() Method

jQuery $.proxy method in jQuery is used to add events to an element where the context is pointing back to a different object and returns a new one with a particular context.


Parameter Values

Parameter Description
function To call the existing function
context Where the function lies to the name of the object
Name Context will be of the existing function
Here is an Example of jQuery $.proxy() Method:

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
var objPerson = {
name: "Alexa",
age: 38,
test: function(){
$(".txt").after("Name: " + this.name + "<br> Age: " + this.age);
$(".btn1").click($.proxy(objPerson, "test"));
<button class="btn1">click to run test function</button>
<p class="txt"></p>