jQuery Toggle Text?

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

    Main Text

    (function() { var mainText = $('.mainText').text(), altText = 'Alt Text'; $('#changeText').on('click', function(){ $(this).toggleClass('altText'); $('.mainText').text(mainText); $('.altText').text(altText); }); })();

提交回复
热议问题