views:

28

answers:

2

I'm using jQuery to manipulate table rows that are paired within a table. I'm trying to select rows based on found items from my previous jQuery where if the row contains a visible image, I need that row and it's next sibling. I can get the row using:

$("img[src*='file.png']:not(:hidden)").closest("tr");

Because I'm also after the sibling row, it seemed logical to me that the next selector would work:

$("img[src*='file.png']:not(:hidden)").closest("tr+next");

The first query produces the first row of the pair, but the second query returns nothing. Am I misinterpreting the documentation - I thought the selector was:

$("prev+next");

I obviously seem to be missing something here...

+1  A: 
var temp;
temp = $('whatever').closest('tr').add( temp.next() )

Also

var temp = $('whatever').closest('tr'); temp = temp.next().andSelf()
meder
That does return the ancestor's next sibling but not the ancestor itself, I need both together.
BenAlabaster
oh, misread. try this?
meder
That could work... it seems a bit long winded. But in a pinch, I may end up using this.
BenAlabaster
it works. you can also use andSelf.
meder
$('whatever').closest('tr').next().andSelf() should therefore work omitting the need for temp...
BenAlabaster
Your variation inspired my solution, thanks.
BenAlabaster
And what was that? I would think `andSelf` referred to the initial object and not the `.closest` so your `$('whatever').closest('tr').next().andSelf()` will probably return `whatever`, I could be wrong.
meder
It *appears* from my testing that it works on the result of .closest() not the result of the initial object.
BenAlabaster
that was the very first thing I thought of, too but I dismissed it because I didnt think it returned the `prevObj`. Guess I was wrong, didn't expect that level of magic.
meder
Well, either way, it worked ;)
BenAlabaster
A: 

I haven't tested this, but what about?

$("img[src*='file.png']:not(:hidden)").closest("tr+tr");

Sniffer
Haha, don't tell me I interpreted the documentation too literally? LOL... If that's it, I'm going to go and drown myself :P
BenAlabaster
Hmm, this looks like it should work, but only appears to return the first row of the pair.
BenAlabaster
I think it's interpreting this as find the closest "tr+tr", of course there is no closest "tr+tr", in the absence of that, I think I need .closest ("tr").add($(this).next()) as suggested by @meder
BenAlabaster