2

Using jQuery, I can use x.next() to get the next element only if it matches my selector. I can use x.nextAll() to get all next siblings that match my selector. And I can use x.nextUntil() to get all next siblings until one matches my selector.

But how can I get the next element that matches my selector?

Jonathan Wood
  • 65,341
  • 71
  • 269
  • 466

1 Answers1

2

You could combine both:

var matchElement = $('elem').nextUntil('matchSelector').next();

or

var matchElement = $('elem').nextAll('matchSelector:first'); //$('elem').nextAll('matchSelector').first();
PSL
  • 123,204
  • 21
  • 253
  • 243