Just a quick one. I am trying to work it the next element that is visible of a cl开发者_Go百科ass and then select a class contained within it.
The first I retrieve like this.
var panelnext = $('.sidewrapper:visible').next();
Now to get the class within it I tried this
var paneltarget = $('.sidewrapper:visible').next('.panelcontent');
That did not work unfortunately. Any ideas?
Marvellous
Do you mean $('.sidewrapper:visible').next().find('.panelcontent')
?
$('.sidewrapper:visible').next().find('.panelcontent');
When you say "within," you probably want find
(for finding descendant elements) rather than next
, which is for siblings. You may want to combine it with :first
to stop at the first match, if you only want one match.
If you really do mean a sibling, rather than a descendant, you may want nextAll
(perhaps combined with :first
) rather than next
. next
will match the immediate sibling element if it matches the selector, or nothing; it never goes beyond the immediate sibling (behavior I found surprising when I first encountered it). nextAll
will search the following siblings for matching elements (and so could skip some non-matches), and of course when combined with :first
will stop at the first match.
精彩评论