I have a scenario where I would like to select rows from a table depending upon the values in td
e.g. I have a table like this
-
You can use the native DOM cells property on the HTMLTableRowElement to access the cells directly, rather than sending jQuery on a roundabout trip with listing all descendant cells and picking out one with the non-standard :eq
selector.
$('tr').each(function (index) {
if (
$(this.cells[0]).text().trim()===x &&
$(this.cells[1]).text().trim()===y
) {
...
}
});
though it probably won't make a serious performance difference. Another approach would be simply to maintain an array-of-arrays containing the pre-trimmed data to save even looking at the DOM.
- 热议问题