Skip to content

Instantly share code, notes, and snippets.

@jeremypage
Created October 17, 2017 13:42
Show Gist options
  • Save jeremypage/f2742bfb229335b860ac72163ef8487e to your computer and use it in GitHub Desktop.
Save jeremypage/f2742bfb229335b860ac72163ef8487e to your computer and use it in GitHub Desktop.
JavaScript / jQuery: Add 'Show more / show less' link at bottom of block to show/hide more content
$(function () {
// Hide the extra content initially (or could be done using css / inline style attribute)
$('.more-content').hide();
// Add 'show more' text beneath the main content
$(".more-less").append('<div class="adjust" style="cursor:pointer">Show more \u25bc</div>');
// Show hidden content when 'show more' selected
$('.more-less').on('click', '.adjust', function (e) {
$(this).siblings('.more-content').slideToggle();
// Change to 'show less' when extra content is visible
($(this).text() === 'Show more \u25bc') ? $(this).text('Show less \u25b2') : $(this).text('Show more \u25bc');
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment