<h1 class='title'>More / less links example</h1>
<p class="text">Cake dessert sweet oat cake marzipan. Pie cupcake marshmallow dragée caramels icing gummi bears lemon drops jelly. Gingerbread topping chupa chups cake cheesecake pudding gummies. Lollipop dessert bear claw. Topping ice cream soufflé lollipop pudding jelly-o. Sweet jelly cotton candy tiramisu cotton candy. Candy jujubes cookie macaroon caramels topping liquorice. Tiramisu cookie cake halvah chocolate bar candy canes lemon drops icing pie. Cake cake marshmallow bear claw gummi bears cupcake. Ice cream lemon drops lemon drops cookie fruitcake chocolate cheesecake lemon drops powder. Tootsie roll gummi bears gummi bears lemon drops gummies sweet roll brownie toffee cake. Lollipop topping ice cream gummies apple pie chupa chups soufflé candy.</p>
<p class="text">Powder lemon drops cake gingerbread marshmallow cake lemon drops. Tootsie roll apple pie sesame snaps toffee. Tootsie roll cheesecake macaroon tootsie roll. Liquorice jelly gummi bears ice cream. Gummi bears tart marshmallow pastry danish biscuit marzipan marshmallow. Dragée pie bonbon croissant lemon drops gummies biscuit chocolate cake muffin. Jelly carrot cake gummies gummi bears biscuit jujubes jelly beans bonbon tiramisu. Cheesecake chocolate bar cookie lemon drops. Cheesecake bear claw macaroon pastry macaroon jelly-o pie. Cheesecake gummi bears gummies. Jelly dessert pudding jelly wafer candy cupcake. Jelly beans sweet roll toffee apple pie candy. Jelly cake gummies cookie pudding topping. Croissant candy canes chocolate chocolate chupa chups croissant cheesecake pie chocolate cake.</p>
.title
text-align: center
color: #C2A878
.text
padding: 10px
font-size: 18px
color: #14281D
.ellipsis
color: #14281D
.more, .less
color: #355834
text-decoration: none
font-weight: bold
padding: 0 5px
.fa
margin: 0 5px
View Compiled
function moreLess(initiallyVisibleCharacters) {
var visibleCharacters = initiallyVisibleCharacters;
var paragraph = $(".text")
paragraph.each(function() {
var text = $(this).text();
var wholeText = text.slice(0, visibleCharacters) + "<span class='ellipsis'>... </span><a href='#' class='more'>MORE<i class='fa fa-arrow-circle-o-down' aria-hidden='true'></i></a>" + "<span style='display:none'>" + text.slice(visibleCharacters, text.length) + "<a href='#' class='less'> LESS<i class='fa fa-arrow-circle-o-up' aria-hidden='true'></i></a></span>"
if (text.length < visibleCharacters) {
return
} else {
$(this).html(wholeText)
}
});
$(".more").click(function(e) {
e.preventDefault();
$(this).hide().prev().hide();
$(this).next().show();
});
$(".less").click(function(e) {
e.preventDefault();
$(this).parent().hide().prev().show().prev().show();
});
};
moreLess(300);
This Pen doesn't use any external CSS resources.