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

288
Visualizações
i want to hide the showmore button if the height of the div(ccontainer) is less than 550px

i want to hide the showmore button if the height of the div(ccontainer) is less than 550px and i will have more than one div and for each i will have a showmore button, and i already have a code that works (hides the btn) but it doesn't work for more than one button like if there are two divs it will hide the button of the first div but it just ignores the second one maybe that is because the code is implemented from top to bottom, so to sum it up what i want to do is that if div's height is less than 550px the show more button should be hidden and the code should also hide the second button for the second div.

and sorry for my broken English

code

js

// showmore btn show/hide
const btn = document.querySelector('.showmore');
const height = document.querySelector('#ccontainer').clientHeight;
btn.forEach(function(){
if (height <= 530) {btn.style.display = 'none';} else {btn.style.display = '';}
)}

html

<div class="ccontainer" id="ccontainer">
  <p id="context"> content </p>
  <div class="img" id="cntimgcon" >
    <img src="images\image2.jpg" id="cntimgp1">
</div>
<p id="context"> content </p>
</div>
<Button class="showmore"> show more </button>
about 4 years ago · Santiago Gelvez
1 Respostas
Responde à pergunta

0

Your question is not fully understandable.But I think you are asking that hide the top most showmore button and display other showmore button when the upper ccontainer is less than 500px.Your styling of the button looks not good to me,but I didnt change it since this is a jquery question. Inorder to test this code I duplicate same html code you have provided. And added image url for display the image since you didnt provide image resource.And I added window.onload function in order to execute your targeted function after the page loads. working sanbox.

I need to mention that you used const btn= document.querySelector('.showmore').But It should be change to const btn =document.querySelectorAll(".showmore");. querySelector only select the first element but querySelectorAll return you a list of node.

html code

 <div class="ccontainer" id="ccontainer">
      <p id="context">content</p>
      <div class="img" id="cntimgcon">
        <img
          src="https://crdms.images.consumerreports.org/c_lfill,w_470,q_auto,f_auto/prod/cars/chrome/white/2018TOC310001_1280_01"
          id="cntimgp1"
          height="25px"
          width="auto"
        />
      </div>

      <p id="context">content</p>
    </div>
    <button class="showmore">show more</button>
    <div class="ccontainer" id="ccontainer">
      <p id="context">content</p>
      <div class="img" id="cntimgcon">
        <img
          src="https://crdms.images.consumerreports.org/c_lfill,w_470,q_auto,f_auto/prod/cars/chrome/white/2018TOC310001_1280_01"
          id="cntimgp1"
          height="25px"
          width="auto"
        />
      </div>

      <p id="context">content</p>
    </div>
    <button class="showmore">show more</button>

js code

  <script>
    window.onload = function () {
      const btn = document.querySelectorAll(".showmore");

      const height = document.querySelector("#ccontainer").offsetHeight;
      btn.forEach(function (single, index) {
        if (height <= 500 && index == 0) {
          single.style.display = "none";
        } else {
          single.style.display = "block";
        }
      });
    };
  </script>
about 4 years ago · Santiago Gelvez 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