Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

179
Views
How to add a readmore button if the length of a text is greater than a value

I am trying to show a read more button if a length of a comment is greater than 80 characters. this is how i check it

<tr repeat.for="m of comments">
<td if.bind="showLess">${m.comment.length < 80 ? m.comment:m.comment.substr(0,80) + " ... "}</td>
</tr>

so if its greater than 80 it shows the "..." but at the end of the dots i wanted to add a button so i tried this

 <td if.bind="showLess">${m.comment.length < 80 ? m.comment:m.comment.substr(0,80) + " ...<button>Read More</button> "}</td>

but then it messes up my html structure and shows it as

enter image description here

how do i structure the html correctly with in ${this function} ?

i cant add the button after the $ { } because then it will show up even if the characters are less than 80.

Note: i didnt use ellipsis because i need the character length

about 4 years ago · Santiago Gelvez
1 answers
Answer question

0

Not sure if this will help but I think using character length is not a good idea here is why:

iiiiiiiiiiiiiiiiiiii...

mmmmmmmmmmmmmmmmmmmm...

Both of these lines have 20 characters but the width of the line is drastically different (unless you are using a font which has similar width chars).

I suggest you do this with CSS by clipping lines according to your need with following code:

display: '-webkit-box',
'-webkit-line-clamp': <number of lines>,
'-webkit-box-orient': 'vertical',
overflow: 'hidden',

Replace number of lines with number of lines of text in that particular div.

For more or less you can use a span tag instead of a button, give it position absolute and place it after the text.

about 4 years ago · Santiago Gelvez Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!