Toggle Bootstrap button text on button click?

后端 未结 5 678
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-19 06:37

I want to toggle the text on a button each time it\'s clicked, e.g. from \"Show more...\" to \"Show less...\".

I have a button that\'s used to expand or collapse a n

5条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-19 07:06

    I tried a couple of these approaches before cobbling this one together. It is the simplest, most readable approach I've seen so far:

        
          View Filters
          Hide Filters
        
    
        
    Now you see me!

    The main purpose of this link is to toggle visibility of div#filters...but it takes advantage of multiple selectors in data_target to also toggle the visibility of the two versions of the link text. Just make sure you've got one text as ".collapse .in" and the other as ".collapse .out".

    Beyond its simplicity, I like that this is very reliable. Because the tag is never hidden or manipulated, you'll never accidentally lose the view/hide link while debugging.

提交回复
热议问题