jQuery Toggle Text?

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

    Modifying my answer from your other question, I would do this:

    $(function() {
     $("#show-background").click(function () {
      var c = $("#content-area");
      var o = (c.css('opacity') == 0) ? 1 : 0;
      var t = (o==1) ? 'Show Background' : 'Show Text';
      c.animate({opacity: o}, 'slow');
      $(this).text(t);
     });
    });
    

提交回复
热议问题