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 -->