Level 50
Jan 16, 2019
5
Level 1
read more in paragraph
hi all
i have post that i want to have read more link to show the rest of the post in the same page like this: i print the post {!! $post->description !!}
A paragraph (from the Ancient Greek παράγραφος paragraphos, "to write beside" or "written beside") is a self-contained unit of ...read more
How to do that?
Level 50
@FATIMA1 blade (HTML) part:
<p>
{{ str_limit($post->description, 100, '') }}
@if (strlen($post->description) > 100)
<span id="dots">...</span>
<span id="more">{{ substr($post->description, 100) }}</span>
@endif
</p>
<button onclick="myFunction()" id="myBtn">Read more</button>
CSS part:
#more {display: none;}
JS part:
function myFunction() {
var dots = document.getElementById("dots");
var moreText = document.getElementById("more");
var btnText = document.getElementById("myBtn");
if (dots.style.display === "none") {
dots.style.display = "inline";
btnText.innerHTML = "Read more";
moreText.style.display = "none";
} else {
dots.style.display = "none";
btnText.innerHTML = "Read less";
moreText.style.display = "inline";
}
}
2 likes
Please or to participate in this conversation.