I have a long sentence showing ellipsis at the end.
I want to use jquery to detect if ellipsis is there, a popup will show up.
But somehow popup doesn’t show when the page loads.
Please give me a hand.
var e = $('.text')[0];
if (e.scrollWidth > e.clientWidth) {
alert("Ellipsis")
}
.text {
-webkit-line-clamp: 5;
-webkit-box-orient: vertical;
display: -webkit-box;
overflow: hidden;
text-overflow: ellipsis;
}
.width{
width: 30%
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="width">
<div class="text"> Lorem ipsum dolor sit amet, consectetur adipisicing elit. Ad recusandae perspiciatis accusantium quas aut explicabo ab. Doloremque quam eos, alias dolore, iusto pariatur earum, ullam, quidem dolores deleniti perspiciatis omnis.</div>
</div>
2
Answers
Just check the size of the text and the container, text element just trigger a overflow over it’s parent, but with ellipsis this is not visible, at least that’s a way to understand it
Here is a way to check if text is ellipse or not:-