jQuery Toggle Text?

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

    this is not the very clean and smart way but its very easy to understand and use somtimes - its like odd and even - boolean like:

      var moreOrLess = 2;
    
      $('.Btn').on('click',function(){
    
         if(moreOrLess % 2 == 0){
            $(this).text('text1');
            moreOrLess ++ ;
         }else{
            $(this).text('more'); 
            moreOrLess ++ ;
         }
    
    });
    

提交回复
热议问题