jQuery Toggle Text?

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

    $(function() {
        $("#show-background").click(function () {
            $("#content-area").animate({opacity: 'toggle'}, 'slow'); 
        });
    
        var text = $('#show-background').text();
        $('#show-background').text(
            text == "Show Background" ? "Show Text" : "Show Background");
    });
    

    Toggle hides or shows elements. You could achieve the same effect using toggle by having 2 links and toggling them when either is clicked.

提交回复
热议问题