chobo2
chobo2

Reputation: 85765

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

Upvotes: 4

Views: 8977

Answers (4)

BalusC
BalusC

Reputation: 1108712

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.

Upvotes: 4

andres descalzo
andres descalzo

Reputation: 14967

var list = [];
$("table").find("tr td:eq(1):not(:contains('0'))").each(function(i,val){
    list.push($(this).parent()); //add TR
});

Upvotes: 0

Gumbo
Gumbo

Reputation: 655239

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.

Upvotes: 5

JAL
JAL

Reputation: 21563

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.

Upvotes: 0

Related Questions