jQuery Toggle Text?

后端 未结 20 1005
日久生厌
日久生厌 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:25

    Why not keep track of the state of through a class without CSS rules on the clickable anchor itself

    $(function() {
        $("#show-background").click(function () {
            $("#content-area").animate({opacity: 'toggle'}, 'slow');
            $("#show-background").toggleClass("clicked");
            if ( $("#show-background").hasClass("clicked") ) {
                $(this).text("Show Text");
            }
            else {
                $(this).text("Show Background");
            }
        });
    });
    

提交回复
热议问题