Greater than selector in jquery?
I have a table that has some rows in it.
Here is an example of my table just with alot less table rows.
<table>
<tr>
&l开发者_运维百科t;td>bob</td>
<td class="CheckThis">0 </td>
</tr>
<tr>
<td>Jim</td>
<td class="CheckThis">3</td>
</tr>
</table>
Now I want to look at the second table cells and get rows back that have value greater then 0.
So in my above example it would get the entire row that contains "3" since it is greater then zero.
I don't see any sectors that do greater then something in jquery but I could have just missed it.
thanks
Try this:
$("tr").filter(function() {
return parseInt($(this).children("td.CheckThis").text(), 10) > 0;
})
This will select you each TR element that has a TD child element with the class CheckThis that’s content is greater than 0.
You can use the filter()
function for this.
E.g.
var tds = $('td.CheckThis').filter(function() {
return parseInt($(this).text()) > 0;
});
Update: after rereading the question once more, you actually want to select the tr
elements containing the td
's in question and thus not only the td
's. In this case, please checkout Gumbo's answer for another code example which does that right.
Sure, gt should do it. Check out the docs at Selectors/gt
Edit: Oh, you're talking about the value in the HTML of the element? You'd probably have to set up a .each loop with a filter or something. I'll check on this, sorry.
var list = [];
$("table").find("tr td:eq(1):not(:contains('0'))").each(function(i,val){
list.push($(this).parent()); //add TR
});
精彩评论