Question: I have to filter a html-table. To do so I created an each callback for all `tr` elements and test if one of the `tr-children` contain some specific pattern.

```
$("#filter").keypress(function() {
    var filter = $(this).val();

    $("#table1 tr[data-config]").each(function(){

        var val = $(this).find(":contains('" + filter + "')");

        if(val.length > 0){
            $(this).css("display","table-row");
        }else{
            $(this).css("display","none");
        }
    });
});

```

It works, but is there an function to test if a element contains some text? 

At the moment I retrieve a list of all elements containing the pattern and count if it's bigger than zero. Is there a jQuery function, which tests if this pattern occurs and returns a boolean? The table can contain many rows and therefore I want as little overhead as possible.

Answer: 
The answers are good, but there's an easier way using :contains

In general, do this:

```
$(".class:contains('texttofind')").css("display", "none");

```

With the specific example above, do this:

```
$("#table1 tr[data-config]:contains('" + filter + "')").css("display","table-row");

```

You can find out more here: <https://api.jquery.com/contains-selector/>

This avoids having to loop with `.each` or `.find`.
When the filter is case sensitive, this is how to make it insensitive:

```
.match("/pattern/i"); 

```

props to [Billy](https://stackoverflow.com/questions/11824022/test-if-children-contain-specific-text-with-jquery/11824143#11824143)!