I'm an experienced developer with not so much experience in jQuery.
I have a table row (<tr>
) element and I'd like to use jQuery to get the next table row that A) is visible, and B) does not have the attribute id='count-me-out'
.
I think I could do this in a loop (although I have some question about checking visibility regardless of what attributes are being used to control visibility). But what what I'd really like is to pass a selector argument to $(myTr).next()
that would implement this filter.
Is this possible?
jQuery next() Method The next() method returns the next sibling element of the selected element. Sibling elements are elements that share the same parent. The DOM tree: This method traverse forward along the next sibling of DOM elements.
To achieve the best performance when using :visible to select elements, first select the elements using a pure CSS selector, then use . filter(":visible") . Using this selector heavily can have performance implications, as it may force the browser to re-render the page before it can determine visibility.
If you want to check visibility instead of display, you should use: . css("visibility") == "hidden" .
Answer: Use the jQuery :visible Selector You can use the jQuery :visible selector to check whether an element is visible in the layout or not. This selector will also select the elements with visibility: hidden; or opacity: 0; , because they preserve space in the layout even they are not visible to the eye.
http://jsbin.com/apaxev/1/edit
var lookingFor = $(this).nextAll('tr:visible').not('#count-me-out').first();
Or like:
var lookingFor = $(this).nextAll( 'tr:visible:not("#count-me-out"):first ');
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With