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

309
Visualizações
Hiding div if string contains specific text

I'm trying to hide 2 separate divs based on the contents of the second one (ie, if the P contains the word "None").

<div class="fusion-text fusion-text-9 fusion-text-no-margin" style="color:#000000;margin-bottom:5px;">
  <p><strong>Twitter :</strong></p>
</div>
<div class="fusion-text fusion-text-10" style="margin-right:60px;" id="twitter-handle">
  <p>None</p>
</div>

I'm able to hide the div with the ID of twitter-handle by using the following:

$(document).ready(function () {
   $("#twitter-handle p:contains('None')").parent('div').hide();
});

However, I can't seem to figure out how to also hide the first div, with the class "fusion-text-9" (it's unique on the page).

Any guidance would be appreciated!

about 4 years ago · Juan Pablo Isaza
3 Respostas
Responde à pergunta

0

to also hide the first div, with the class "fusion-text-9"...

$(document).ready(function () {
   $("#twitter-handle p:contains('None')").parent().parent().hide();
});
<div class="fusion-text fusion-text-9 fusion-text-no-margin" style="color:#000000;margin-bottom:5px;">
  <p><strong>Twitter :</strong></p>
</div>
<div class="fusion-text fusion-text-10" style="margin-right:60px;" id="twitter-handle">
  <p>None</p>
  
  <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js"> </script>
</div>

about 4 years ago · Juan Pablo Isaza Relatório

0

If you want a vanilla JS solution instead of using jQuery you can use the match() method on the element's text content:

let fusionText = document.querySelectorAll(".fusion-text");

fusionText.forEach(element => {
  if (element.textContent.match(/None/)) {
     fusionText.forEach(element => {
         element.style.display = "none";
     })
  }
});
<div class="fusion-text fusion-text-9 fusion-text-no-margin" style="color:#000000;margin-bottom:5px;">
  <p><strong>Twitter :</strong></p>
</div>
<div class="fusion-text fusion-text-10" style="margin-right:60px;" id="twitter-handle">
  <p>None</p>
</div>

further reading

More here about match() and textContent()

about 4 years ago · Juan Pablo Isaza Relatório

0

The prev method should be what your looking for...

$(document).ready(function () {
    var $found = $("#twitter-handle p:contains('None')").parent('div');
    $found.hide();
    $found.prev().hide();
});

You can also pass a selector to the prev method...

$(document).ready(function () {
    var $found = $("#twitter-handle p:contains('None')").parent('div');
    $found.hide();
    $found.prev('.fusion-text-9').hide();
});
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