Search code examples
jqueryhideinnertext

Jquery find a div with innertext and hide


I have a div as below that i need to hide the specific div based on the inner text clause.

  1. Hide div when inner text is equal to a word XXX
  2. Hide div when inner text contains a word XXX
<div>first div <div>second div <div>third div <div style="position: absolute; padding: 2px; top: 0px; left: 1px; color: white;">XXX</div>/div>/div>/div>

Solution

  • Try this:

    $('div:contains("XXX")').hide().parents('div').show();
    // hides the div which holds the word 'XXX' and shows the parent
    

    Demo