Q:

Update element text when clicked

$("#readMain").delegate("span", "click", function() {
    var toSend = $(this).text();
    $(this).text(function() {return "test1";});
    $.post('/render/', {'word': toSend}, function(data){
        $(this).text(data);
        alert(data); //for testing
    });
});

I'm trying to have the word clicked updated. It works fine the first time (it changes to 'test1'), but after the post call, it doesn't work anymore?
What am I doing wrong

A:

This in that context refers the first time to the "span", the second time it refers to the window object.
Besides that, delegate is old jQuery, you can use '.on' now.
You'll nee to update the function like this: 
$("#readMain").on("click", "span", function() {
    var span = $(this);
    var toSend = span.text();
    $.post('/render/', {'word': toSend}, function(data){
        span.text(data);
        alert(data); //for testing
    });
});

