I have a large block of text with half of the text hidden. I'm using a Bootstrap 5x toggle to show and hide the block of text. This works fine.
However, I am also trying to change the button text from Show more to Show less when the toggle takes place. I have some jQuery that should work but it is not. The text does not change from Show more to Show less.
Here is the Toggle code:
<div class="collapse more-collapse" id="moreContent{sub_topic:entry_id}">
{sub_topic:more_text}
</div>
<p><a class="red more-toggler custom-toggler me-4" data-bs-toggle="collapse" data-bs-target="#moreContent{sub_topic:entry_id}" aria-controls="moreContent" aria-expanded="false" aria-label="Toggle more-content">
Show <span>more</span><span class="hidden">less</span> ›</a></p>
And here is the jQuery (running jQuery 3.7.1):
$(document).ready(function() {
$('.hidden').removeClass('hidden').hide();
$('.toggle-text').click(function() {
$(this).find('span').each(function() { $(this).toggle(); });
});
});