Using $(this) in a callback function

I have created a click event handler on an anchor and can reference it using $(this) just fine until I include a $.post function which processes the return data using a callback function. Once in the callback function, the $(this) no longer works.

How can I refer to the clicked anchor from within the $.post callback function? After way too long trying different combinations of things and making it work and break, I am first of all assuming that is what is going on, i.e. that once I am in the callback function, I no longer have access to $(this).

Anyhow, any advice would be welcome at this point.


Before your $.post callback add

var thisname = $(this);

You can name it anything but a javascript predefined reserved word, then when you want to call $(this) just replace that with for exmaple


Brilliant. Thank you, thank you, thank you. Funny, I almost tried that but at 1:30 in the morning my inquisitiveness was about tapped out. Just tried it now and it works like a champ. Have a great day.

Your welcome

An inline function can also be used to bind a reference rather than populating the outer function with unnecessary variables.

	url: '--'
	,success:(function(me) {
		return function(data,status,xhr) {