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 nearby block (see the Collapse section of the Bootstrap docs, click the example "Link with href" button there to see what I mean).
The HTML for such a Bootstrap button looks like this:
<a class="btn btn-primary" data-toggle="collapse" href="#collapseExample">
See more...
</a>
When the related block is collapsed I want the button text to be e.g. "Show more..." and when it's expanded I want it to be e.g. "Show less...".
I've seen solutions that separate the button text off into jQuery, Javascript or CSS - but that makes it difficult to read the HTML (the button text is somewhere else entirely to the button) and also makes it more difficult to localize.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…