My task involves filtering an HTML table. In order to accomplish this, I have created an 'each' callback for all 'tr' elements and check if any of their children contain a 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");
}
});
});
The current method works well, but I'm wondering if there is a function that can directly test if an element contains certain text?
Currently, I am retrieving a list of all elements with the pattern and checking if the count is greater than zero. Is there a jQuery function that can efficiently determine if the pattern exists and return a boolean value? Since the table may have numerous rows, I aim to minimize unnecessary overhead.