Amit Dhamu

Writes Code

Toggle Text Function

// Function
jQuery.fn.toggleText = function(v1, v2) {
    return this.each(function() {
        var element = $(this),
             text = element.text();

        if(text.indexOf(value1) > -1) {
            element.text(text.replace(v1, v2));
        } else {
            element.text(text.replace(v2, v1));
        }
    });
}

// Usage
// When this is called, all instances of Yes are replaced with No and vice-versa
$("p").toggleText("Yes", "No");


text / toggle / functions / jquery

← Useful Folder & File Functions in PHP HTTP Authentication →