Reputation: 67195
I recently posted the question Get Next Element that is Visible and Does Not Have Attribute, in which I asked how to get the next sibling that is both visible and does not have the attribute id='count-me-out'
.
The upshot was the following syntax which appears to work great:
var trNext = $(tr).nextAll('tr:visible:not("#count-me-out"):first');
I now have a variation on this where I want to use the exact same filter except that I want to return the current element (tr
in the example above) if it passes the filter. If it does not, then I want to proceed by looking at the next one. In other words, it would work exactly like the line above except starting with the current element rather than the next one.
I guess one approach is to use prev()
to get the previous sibling and then use the line above to get the next matching one. Can anyone say if there's a better way?
Upvotes: 0
Views: 535
Reputation: 97672
Try
var trNext;
if ($(tr).is('tr:visible:not("#count-me-out")')){
trNext = tr;
}
else{
trNext = $(tr).nextAll('tr:visible:not("#count-me-out"):first');
}
Upvotes: 1