Sam Su Sam Su - 6 months ago 29
jQuery Question

JQuery multiple selector with next() sibling

As we know:

$('#a').addClass('current');
$('#b').addClass('current');
$('#c').addClass('current');




$('#a, #b, #c').addClass('current');


But, can jQuery get multiple selectors with
next()
sibling?

$('#d').next().addClass('current');
$('#e').next().addClass('current');
$('#f').next().addClass('current');


actually I mean if we can reference all of these selector (a, b, c, d's next, e's next, f's next) in one line?

Answer

The same way you can

$('#d,#e,#f').next().addClass('current');

UPDATE : I think you need to combine both the selector, then put them inside an array and wrap with jQuery.

$([$('#a, #b, #c'), $('#d,#e,#f').next()]).addClass('current');

or use next adjacent sibling selector(+) instead of next() method

$('#a, #b, #c, #d + * , #e + *, #f + *').addClass('current');