JQuery :contains find first and single instance of a string
The Jquery :contains function is very good in that it will find an instance of a string. However what if I am performing this contains: function on a table which in the second column contains the following.
0
20
01
44
The code below when run on the above table with the column values will return every row where there is a "0". SO basically every row except "44".
$('.application>tbody>tr')
.show()
.f开发者_运维技巧ind("td:nth-child(2).not(':contains("0")')
.parent()
.hide()
}
How would one go about making the code return only the rows where there is a single "0" and not the other rows which contain a "0" such as "20".
Hope someone can point me in the right direction. Thank you.
You can use .filter()
for this, for example:
$('.application>tbody>tr')
.show()
.find("td:nth-child(2)")
.filter(function() { return $.text([this]) != "0"; })
.parent()
.hide()
This compares the exact text, rather than a substring.
精彩评论