I have card with my properties, where is also description (fetched from DB), but since it is too long I need to hide most of it and show it again with "read more" button. I know the solution for hard-coded text, but I don't know how to apply it for fetched data.
I am thinking of something like this:
<p class="card-text"><?php
if(strlen($fetch['description']) > 50) {
echo '<a href="#" class="read-more">Show More</a>';
} else {
// SOLUTION HERE
}
?></p>
jQuery for changing show-more-show less:
$(document)
.on('click','.read-more',function() {
$(this).removeClass('read-more').addClass('show-less').html('Show Less').prev('.description').removeClass('ellipsis');
})
.on('click','.show-less',function() {
$(this).removeClass('show-less').addClass('read-more').html('Read More').prev('.description').addClass('ellipsis');
});