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

221
Views
How to hide button when there are no dots of elipsis

I have this case I want to hide the button if there are no dots, if the dots appear show the read more button. I need it to be this way two lines and dots appear after this width. Is there a way to do it on Javascript pure? Please help

.text {
  max-width: 400px;
  overflow: hidden;
  text-overflow: ellipsis;
  -webkit-line-clamp: 2;
  display: -webkit-box;
  -webkit-box-orient: vertical;
}

.wrapper {
  display: flex;
  align-items: end;
}

button {
  padding: 0;
  background: white;
  border: none;
  line-height: 3.5;
}
<div class="wrapper">
  <p class="text">Some dummy text hereSome dummy text hereSome dummy text hereSome dummy text hereSome dummy text hereSome dummy text here </p>
  <button>Read more</button>
</div>

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

This would be just one variation using JS. In this example, the ellipsis effect is simulated with a span so the text is truncated. The hidden text is using display: none; and the JS toggles it to display: inline;. It also changes the HTML in the button text with text.innerHTML = "Read less";.

function myFunction() {
    var dots = document.getElementById("dots");
    var moreText = document.getElementById("more-text");
    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";
    }
}
.wrapper {
  width: 100%;
}

.text {
  max-width: 400px;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: auto;
  -webkit-box-orient: vertical;
}

#more-text {
  display: none;
}

button#myBtn {
  padding: 0;
  background: white;
  border: none;
  line-height: 3.5;
  margin: auto;
}

p {
  margin: 0;
}
<div class="wrapper">
   <p class="text">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus imperdiet, nulla et dictum interdum, nisi lorem<span id="dots">...</span><span id="more-text"> tellus gravida venenatis. Integer fringilla congue eros non fermentum. Sed dapibus pulvinar nibh tempor porta.</span></p>
   <button onclick="myFunction()" id="myBtn">Read more</button>
</div>

about 4 years ago · Juan Pablo Isaza 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!