Q:

Change back from text() to original text

I'm using jQuery to change text on a clicked element.
But how do I change the text back to the original text?
$(".myClass").click(function() {
        $(this).text("You clicked me!");
    });

I want to be able to click on .myClass again and get the original text...is there something comparable to "toggle" with text()?

A:

I've written an extension to solve this very problem.  It's only a few lines:
jQuery.fn.extend({
    toggleText: function(stateOne, stateTwo) {
        return this.each(function() {
            stateTwo = stateTwo || '';
            $(this).text() !== stateTwo && stateOne ? $(this).text(stateTwo) : $(this).text(stateOne);
        });  
    }
});

Usage:
$('.myClass').on('click', function() {
    $(this).toggleText('show', 'hide'); //Toggles from hide to show
});

