Created
October 17, 2017 13:42
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$(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