I have a page with multiple divs like this:
`<div class="mod-tile">
Bla bla zbing
<div>Lorem Ipsum</div>
<time class="date">Crocodile Dundee 2016</time>
<div class="date">Lorem lorena 2017</div>
</div>
<div class="mod-tile">
Bla bla zbing
<div>Lorem Ipsum</div>
<time class="date">John Humdee 2016</time>
<div class="date">Izabelle Adjani 2018</div>
</div>
<div class="mod-tile">
Bla bla zbing
<div>Lorem Ipsum</div>
<time class="date">Rabbit wabbit 2017</time>
<div class="date">Bam boom 2020</div>
</div>`
How can I hide, using JQuery, the parent "mod-tile" div if the child div with class "date" contains 2017 as text? Only the "mod-tile" div that contains that, not all other "mod-tile" divs.
My limited knowledge try:
$("div:hasClass("mod-tile"):has(div:hasClass("date"):contains("2017")).hide()")
Thank you
EDIT: So the solution for the above divs is, as mr. Paul T. said:
$(".mod-tile > div.date:contains('2017')").parent().hide();
What happens if the "date" div is nested within another div, and we still need to hide the grandparent "mod-tile"?
<div class="mod-tile">
Bla bla zbing
<div>Lorem Ipsum</div>
<div class="wabbit">
<time class="date">Crocodile Dundee 2016</time>
<div class="date">Lorem lorena 2017</div>
</div>
</div>
Solution for second example, based on Paul's code and using Rory's suggestions:
$(".mod-tile").has("div.date:contains('2016')").hide();
Thank you