Where TD Does Not Contain Text
I'm getting magical with some data filtering. When hitting a drop down list I want to eliminate rows from a table where a certain column does not contain the text from the drop down list. I've tried various combinations without any luck as follows:
开发者_Python百科$("table tr td:contains('" + $("#SupplierID :selected").text() + "')").parent().hide();
This obviously hides the ones that do contain the selected text. I've tried not:contains but that doesn't work at all. So yeah, I want to do the inverse of this. And can I do it for a certain column? There's no point going through all the columns as it only applies to one column.
Cheers!
You can do it like this:
$("table tr td:nth-child(...):not(:contains(...))")
:not(:contains("text"))
Is what you need
Similar approach using jQuery not()
hide rows where the first (or nth) column does not contain the text "DoNotHide"
$('td:nth-child(1)').not($('td:contains("DoNotHide")')).parents('tr').hide()
or, hide all rows that do not have a column with "DoNotHide" text
$('tr').not($('td:contains("DoNotHide")').parents('tr')).hide();
精彩评论