Select the .next() element with a specific attribute JQUERY

corbinan picture corbinan · Jul 26, 2011 · Viewed 8.5k times · Source

This is what I have :

$("#comment").next().attr('shown',0).fadeIn();

I'm trying to show the next comment that is hidden on the page. however, I'm trying to do two comments shown at a time, so if you click the first one, the second one is next. So I've given a shown attribute. I would like to select the NEXT with the attribute shown=0. The above does not work. I believe it would be next(tr[shown=0]) but i can't get that to work (i'm in a table looking for the next row)

any help is appreciated!

Answer

SLaks picture SLaks · Jul 26, 2011

next can only return the immediate next sibling.

You can call nextAll, which returns all subsequent siblings, with the :first selector to get the first matching one:

$(...).nextAll("tr[shown=0]:first")