Tutorial Toggle Text
Let's say you have a link to show more options which expands a list of options. It's says "more options". It's easy to toggle those options with .toggle()
or .slideToggle()
, but the text remains the same. To toggle the text too...
$("#more-less-options-button").click(function() {
var txt = $("#extra-options").is(':visible') ? 'more options' : 'less options';
$("#more-less-options-button").text(txt);
$("#extra-options").slideToggle();
});
There is a bunch of other ways, as well.