I am trying to make a collapse type of thing using jQuery. Everything works fine except I want the text to toggle between "show more models" and "show less models", and I have no clue what to do. Here's the code:
<a id='roll-more' data-toggle="collapse" href=".roll-img2" class="text-dark">
Show more models <span class="glyphicon glyphicon-chevron-down"></span>
</a>
$('#roll-more').toggle(function() {
$('#roll-more').html('Show less models <span class="glyphicon glyphicon-chevron-up"></span>');
}, function() {
$('#roll-more').html('Show more models <span class="glyphicon glyphicon-chevron-down"></span>');
});
EDIT Thanks for all the responses but I ended up doing this instead. Can't believe it was so simple :)))
$('#roll-more').on('click',function() {
if($('#roll-more').html() == 'Show more models <span class="glyphicon glyphicon-chevron-down"></span>') {
$('#roll-more').html('Show less models <span class="glyphicon glyphicon-chevron-up"></span>')
} else {
$('#roll-more').html('Show more models <span class="glyphicon glyphicon-chevron-down"></span>')
}
});