Reputation: 657
I am trying to swap out button text on click. The function of a button is to toggle a <div>
. Is it possible with jQuery to set up two instances of button text and swap them out on toggle?
This is where I am so far:
$('#showmodule').click(function() {
$(this).addClass('active');
$('#module').slideToggle()
});
Upvotes: 0
Views: 1667
Reputation: 6752
What I would do in your case, is add spans inside of your anchor link, and toggle those, such as the following.
<a href="#" id="showmodule">
<span>Default Text</span>
<span style="display : none;">Toggled Text</span>
</a>
And the javascript would look something like this.
$('#showmodule').click(function() {
$(this).addClass('active');
$('span', this).toggle(); // This line will toggle the spans inside of the link
$('#module').slideToggle()
});
Upvotes: 2