Hide divs father if son div has certain text

1

I have an html file with more than 3500 div and I need to create a function with jQuery to hide the div parents if a div child has certain text (eg: "code"). How could I do it?

This is my function, but I can not get it to work properly:

$(".comment").contents( function(){ 
  if (this.value === 0) {
    this.parent.css( "display","none");
  }
}); 

For example- I would like to hide the div parent of div with class "attributeName" and that contains the text "code":

$(".comment").contents(function() {
  if (this.value === 0) {
    this.parent.css("display", "none");
  }
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

<div>
  <div class="attribute">
    <div class="attributeName">AAA</div>
    <div class="attributeComment"></div>
  </div>
  <div class="attribute">
    <div class="attributeName">codigo</div>
    <div class="attributeComment"></div>
  </div>
  <div class="attribute">
    <div class="attributeName">BBB</div>
    <div class="attributeComment"></div>
  </div>
  <div class="attribute">
    <div class="attributeName">CCCC</div>
    <div class="attributeComment"></div>
  </div>
</div>

<!-- Mas de 3000 divs con las mismas clases -->
    
asked by lanshare 13.09.2018 в 22:34
source

1 answer

-1

Hello, this should work for you

$(".attributeName").each(function( index ){
    if($(this).html()=="codigo"){
        $(this).parent().hide();
    }
});
    
answered by 13.09.2018 в 22:52