Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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>
   <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

like image 237
chobo2 Avatar asked Jan 22 '23 19:01

chobo2


2 Answers

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.

like image 81
Gumbo Avatar answered Jan 31 '23 23:01

Gumbo


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.

like image 33
BalusC Avatar answered Jan 31 '23 22:01

BalusC