JSFiddle - React, Tailwind, and code Playground
HTML
<div class="readmore">
<p>
text / text / text / text / text / text / text / text / text / text / text / text / text / text / text / text / text
</p>
</div>
CSS
.overflow {
height: 120px;
overflow: hidden;
}
JavaScript
$(document).ready(function() {
$('.readmore').each(function() {
if ($(this).height() >= 150) {
var p = $('p', this),
a = $('<a>', {
'href': '',
'class': 'click'
});
p.addClass('overflow');
a.text('подробнее');
$(this).append(a);
a.click(function() {
if (p.hasClass('overflow')) {
p.removeClass('overflow');
a.text('скрыть');
} else {
p.addClass('overflow');
a.text('подробнее');
}
return false;
});
}
});
});