Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get Next Element that is Visible and Does Not Have Attribute

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?

like image 971
Jonathan Wood Avatar asked Jan 05 '13 04:01

Jonathan Wood


People also ask

How to get next sibling value in jQuery?

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.

How do you select visible 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.

How do you know if an element is hiding?

If you want to check visibility instead of display, you should use: . css("visibility") == "hidden" .

Is element visible on screen jQuery?

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.


1 Answers

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 ');
like image 97
Roko C. Buljan Avatar answered Sep 23 '22 13:09

Roko C. Buljan