How to compare if an id is more than a value in jquery
Is it possible to use the more than operator in a jquery criteria For e.g say i开发者_运维百科 want to get all rows where the rowindex is more than a certain value. Is it possible somehow or do i need create my own function once I have the result set from jquery?
For the example mentioned in your question, you can just use the :gt()
selector:
// Get all rows with a rowIndex greater than 5:
var rowsPlus5 = $('#mytable tr:gt(5)');
For other scenarios, you might need to use the .filter()
method with a callback function.
var $filtered = $('table').find('tr').filter(function(){
return (this.rowIndex > 5);
});
Works.
It does not work with $('table').children('tr')
, I have no clue why not. Somebody please?
I would try something similar to the following:
$('tr.selector').each(function(){
var rowId = $(this).index();
if (rowId > 5){
$(this).addClass('red');
}
});
you may want:
.slice( start, [ end ] ); Reduce the set of matched elements to a subset specified by a range of indices.
start An integer indicating the 0-based position after which the elements are selected. If negative, it indicates an offset from the end of the set.
end An integer indicating the 0-based position before which the elements stop being selected. If negative, it indicates an offset from the end of the set. If omitted, the range continues until the end of the set.
精彩评论