Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

212
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda