...
<tr>
<td>222</td>
</tr>
<tr>
<td>333 222</td>
</tr>
...
And I have this code for selector:
$("#TableName tr td:contains('222')");
Problem: I need to select the cell that the html is ‘222’ only.
I try use $("#TableName td tr[html=222]") but don’t work.
You can use
.filter()instead to do an exact match.This uses
$.text()to compare the text value of the<td>with"222". It’s just a little quicker way of doing$(this).text(). Gives you the same result. (Note that you need to passthisin an Array[this].)When there’s a match, the element is returned into the resulting jQuery object.
If there’s any possibility of leading or trailing white space in the
<td>, you can trim that with$.trim().EDIT: You could create your own selector that will accomplish the same task if you want: