I need to execute the same code in jQuery multiple times so i decided to make my own jQuery function.
It looks like this so far:
jQuery.fn.extend({
fooFunction: function () {
$.ajax({
type: "POST",
cache: false,
url: "includes/thescript.php",
success: function (data)
{
$(this).html(data);
}, complete: function () {
// do sth
}
});
return $(this);
}
});
But now i have the problem, that "this" seems to refer to the wrong instance, while using it here in the success function "$(this).html(data);".
When i use the ID instead, e.g. $("#TheID").html(data); it works, but why not with "this"?
Between: I call the function with: $("#TheID").fooFunction()