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

  • This topic is empty.
Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
  • #240326

    I have a group of divs that appear on multiple pages, that have this pattern:

    This group appears on multiple pages.

    My ideal javascript/jquery solution is something like this:

    1. hide all div class=”fs-entry-container”
    2. if child div class=”fs-detail-title” contains #something, change parent div class=”fs-entry-container” to display:block — so that on Page A I can insert this code to only show div class=”fs-entry-container” with #sts_com__01js, on Page B only show #sts_com__01gm etc. etc.

    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,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 :)

Viewing 3 posts - 1 through 3 (of 3 total)
  • The forum ‘JavaScript’ is closed to new topics and replies.