Ken Le
Ken Le

Reputation: 1805

How to use jQuery's .not and :contains in case of multiple values?

$("table[id=" + tblName + "] tr").not(":contains('" + val + "')").hide();

This code will hide all TRs not containing "val".

I have "val1" and "val2" in my code. I wish to hide TRs not containing both "val1" and "val2"

How do I do that?

^>^ Thanks for your help.

Upvotes: 1

Views: 1783

Answers (1)

Joseph Marikle
Joseph Marikle

Reputation: 78520

Logically an AND exclusion:

$("table[id=" + tblName + "] tr").not(":contains('" + val1 + "'):contains('" + val2 + "')").hide()

Logically an OR exclusion:

$("table[id=" + tblName + "] tr").not(":contains('" + val + "')").not(":contains('" + val2 + "')").hide();

Upvotes: 6

Related Questions