简体   繁体   中英

How to hide a parent div if children contains a certain text/string?

Here's my code:

 <div class="row word-style table-border">
 <a href="#" target="_blank">
 <div class="col-md-1 underlined">00184799</div>
        </a>

    <div class="col-md-1">  
        Salesforce Case 
    </div>

    <div class="col-md-3">
     Machine Down 
    </div>


    <div class="col-md-1">
        Machine Down
    </div>

    <div class="col-md-1">
        Internal Request
    </div>

</div>

I want to hide the whole entire div if ever the text Internal Request is present.

You need to use the DOM API for this,

$containers = document.querySelectorAll("div.row.word-style.table-border");

for($container of $containers) {
  if ($container.innerText.includes('Internal Request')) {
    $container.style.display = "none" ;
  }
}

check this link

Below code should work for you:

$('.row .col-md-1').each(function(index,col){
    if($(col).text() == 'Internal Request'){
       $(col).hide();
    }
})

Many ways to peel this apple. Here's one:

 var row=document.querySelector(".row"); var children = row.childNodes children.forEach(c=>{ if(c.innerHTML&&c.innerHTML.indexOf("Internal Request") !== -1) { row.className+=" hidden" } }); 
 .hidden{ display: none; } 
  <div class="row word-style table-border"> <a href="#" target="_blank"> <div class="col-md-1 underlined">00184799</div> </a> <div class="col-md-1"> Salesforce Case </div> <div class="col-md-3"> Machine Down </div> <div class="col-md-1"> Machine Down </div> <div class="col-md-1"> Internal Request </div> </div> 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM