2

I wonder if there is a well performing way to find out if .nextUntil() stopped without matching the specified selector.

.nextUntil() returns the same result as .nextAll() if the selector didn't match any element.

So it is possible to find out using:

if ($("#id").nextUntil(".someclass").length === $("#id").nextAll().length) {
  //do some stuff if there was no match
}

But is there a better solution?

cdMinix
  • 655
  • 1
  • 7
  • 29
  • You already have a typo `nextUnil`... so it's probably not gonna match anything :D – T J Jul 18 '14 at 17:22

1 Answers1

1

If it stops without a match, it means that you have a last child inside your object. You can use the following:

if (!$("#id").nextUntil(".someclass").is(':last-child'))

Test it here

cdMinix
  • 655
  • 1
  • 7
  • 29
Karl-André Gagnon
  • 33,662
  • 5
  • 50
  • 75