brentfraser
brentfraser

Reputation: 77

Hide parent DIV when h4 contains certail text

What I'd like to do is try to hide the parent div of the following (it would be hiding the div class called "eB cer") if h4 includes the word "bulk."

<div class="eB cer">
<h4>Bulk Load Files to CERs</h4>
<div class="tooltip"><b>Description: </b>You will add files to your CERs using the Bulk Load and Attribute Update Utility.<span class="tooltiptext">In this module you will learn how to add files to your CERs in bulk and modify any attributes as needed.</span>
</div>
<p><b>Link: </b><a href="http://ebassets.network.lan/eBPrdSC1/eB%20Help/eB%20Help__54.html" target="_blank">Bulk Load Files to CERs</a></p>
</div>

I have this and it's hiding the h4, but not the entire div.

var searched_string = "eB cer"; 
var foundmatch = [];

for(i=0; i < leftFilteredArray.length; i++){
    if(leftFilteredArray[i].match(searched_string)){
        foundmatch.push(leftFilteredArray[i]);
        $("div h4:contains('" + searched_string +"')").hide();
    }

Any suggestions what I'm doing wrong?

Upvotes: 0

Views: 155

Answers (2)

Elish
Elish

Reputation: 486

You can use indexOf() which returns the first index at which the specified string is found. Else it returns -1.

if($('.eB.cer>h4').text().toLowerCase().indexOf('bulk')!==-1)
  $('.eB.cer').hide()

Upvotes: 2

943A
943A

Reputation: 166

To recreate your situation I ended up looking at the jQuery line. Then I plugged it into the rest of the code. Here is what I got working.

var searched_string = "Bulk"; 
var foundmatch = [];

for(i=0; i < leftFilteredArray.length; i++){
    if(leftFilteredArray[i].match(searched_string)){
        foundmatch.push(leftFilteredArray[i]);
        $("div h4:contains('" + searched_string +"')").parent().hide();
    }
}

This line sets the text to lower case for less issues.

var searched_string = "Bulk"; 
var foundmatch = [];

for(i=0; i < leftFilteredArray.length; i++){
    if(leftFilteredArray[i].match(searched_string)){
        foundmatch.push(leftFilteredArray[i]);
        // $("div h4:contains('" + searched_string +"')").parent().hide();
        if( $(".eB.cer h4").html().toLowerCase().indexOf(searched_string.toLowerCase()) > -1) {
            $(".eB.cer").hide();
        }
    }
}

Upvotes: 1

Related Questions