Только по основам:
var extraText = ". Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum";
var originalText;
$('.moreless').click(function() {
if (this.innerHTML === 'More...') {
this.innerHTML = 'Less...'
originalText = $('.textControl')[0].innerHTML;
$('.textControl')[0].innerHTML += extraText;
} else {
this.innerHTML = 'More...'
$('.textControl')[0].innerHTML = originalText;
}
});
<p class='textControl'>
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum
</p>
<button class='moreless'>More...</button>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
Сохраняет текущий текст, когда вы нажимаете «Еще ...» и , затем добавляет дополнительный текст. Это также изменяет текст кнопки на «Меньше ...». Когда текст кнопки говорит «Меньше ...», он возвращается к исходному тексту, который был сохранен как переменная.
Это просто основная идея. Чтобы он показывал по умолчанию только 50 символов, вы делаете это:
var maxText = 50;
var originalText = $('.textControl')[0].innerHTML;
var reducedText = $('.textControl')[0].innerHTML.substring(0, maxText - 1);
$('.textControl')[0].innerHTML = reducedText;
$('.moreless').click(function() {
if (this.innerHTML === 'More...') {
this.innerHTML = 'Less...'
$('.textControl')[0].innerHTML = originalText;
} else {
this.innerHTML = 'More...'
$('.textControl')[0].innerHTML = reducedText;
}
});
<p class='textControl'>
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum
</p>
<button class='moreless'>More...</button>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
Код сохраняет 50 символов при запуске, но также сохраняет исходный текст. То же самое происходит при изменении текста кнопки и текста абзаца.