- This topic is empty.
Viewing 3 posts - 1 through 3 (of 3 total)
Viewing 3 posts - 1 through 3 (of 3 total)
- The forum ‘JavaScript’ is closed to new topics and replies.
The forums ran from 2008-2020 and are now closed and viewable here as an archive.
Home › Forums › JavaScript › Only show parent if child contains certain string
I have a group of divs that appear on multiple pages, that have this pattern:
http://codepen.io/jonymtl/pen/bpamgV
This group appears on multiple pages.
My ideal javascript/jquery solution is something like this:
This should be a start with some jQuery :
$('.fs-entry-container').hide().each(function() {
var text = $(this).find('.fs-detail-title:contains("01gm")');
if (text.length) $(this).show();
});
And a plain JS alternative in case you’re not already using jQuery and want something lightweight http://jsbin.com/yemaqorase/1/edit?html,js,output
EDIT: Sorry, I misread – I thought it was a ‘hide if empty’ rather than ‘ hide if doesn’t not contain X’. Ho hum – I’ll leave the demo in case it’s useful for other projects, or as a starting point for further adaptations by yourself :)