The easy way is to create a closure like this:
$(".testBox").click(function(){
var me = $(this);
me.addClass("backRed");
$.get("/data/TESTer/?tickle=yes", function(data) {
me.addClass("backGreen");
alert("Data Loaded: " + data);
});
});
What this does is:
- create a local scope variable that stores the
$(this)
. - use that variable in the inner-function
What happens is that it will create a closure, a function that has a reference to an outer parent and can use variables from that parent.