Remove table row if first cell of that row contains value greater than 50 and lessthan 100 using jquery?
Sample table:
<table>
<tr开发者_StackOverflow>
<td>14</td>
<td>information</td>
</tr>
<tr>
<td>70</td>
<td>information</td>
</tr>
<tr>
<td>19</td>
<td>information</td>
</tr>
</table>
$("tr td:first-child").each(function() {
var value = parseInt($(this).text(), 10);
if(value > 50 && value < 100) {
$(this).parent().remove();
}
});
This iterates over the first child (which should always be a td
) of each tr
element, gets the text of that child, parses it into a Number, and removes the parent tr
if necessary.
Here's a working example.
Working: http://jsfiddle.net/XX3fV/1/
$.each($('table tr'), function() {
var f = parseInt($(this).first('td').text());
if (f > 50 && f < 100)
$(this).remove();
});
$(function()
{
$("tr").each(function()
{
if(parseFloat($(this).find("td:first").text()) > 50 &&parseFloat($(this).find("td:first").text()) < 100)
{
$(this).remove();
}
});
});
Not tested! http://jsfiddle.net/ahallicks/BZdTP/ or http://jsfiddle.net/ahallicks/BZdTP/1/
http://jsfiddle.net/Vwzya/
$('table tr').each(function () {
if ( $(this).find('td:first').html() > 50 && $(this).find('td:first').html() < 100 )
$(this).remove();
});
Give "mytable" id to table
$('#mytable tr').each(function() {
var var = $(this).find("td").eq(0).html();
if(parseInt(var) > 50 && parseInt(var) < 100)
{
$(this).remove();
}
}
精彩评论