jQuery Toggle Text?

后端 未结 20 981
日久生厌
日久生厌 2020-12-02 05:52

How to toggle HTML text of an anchor tag using jQuery? I want an anchor that when clicked the text alternates between Show Background & Show Text

20条回答
  •  心在旅途
    2020-12-02 06:17

    Use html() to toggle HTML content. Similar to fflyer05's code:

    $.fn.extend({
        toggleText:function(a,b){
            if(this.html()==a){this.html(b)}
            else{this.html(a)}
        }
    });
    

    Usage:

    Toggle me!
    

    Fiddle: http://jsfiddle.net/DmppM/

提交回复
热议问题