Javascript 是否有更好的方法检测nextUntil是否定期停止?

Javascript 是否有更好的方法检测nextUntil是否定期停止?,javascript,jquery,performance,nextuntil,Javascript,Jquery,Performance,Nextuntil,我想知道是否有一种性能良好的方法来确定.nextUntil()是否在不匹配指定选择器的情况下停止 .nextUntil()如果选择器与任何元素不匹配,则返回与.nextAll()相同的结果 因此,可以通过以下方式找到答案: if ($("#id").nextUntil(".someclass").length === $("#id").nextAll().length) { //do some stuff if there was no match } 但是有更好的解决方案吗?如果停止时没

我想知道是否有一种性能良好的方法来确定
.nextUntil()
是否在不匹配指定选择器的情况下停止

.nextUntil()
如果选择器与任何元素不匹配,则返回与
.nextAll()
相同的结果

因此,可以通过以下方式找到答案:

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

但是有更好的解决方案吗?

如果停止时没有匹配项,则表示对象中有最后一个子对象。您可以使用以下选项:

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

您已经有一个打字错误
nextUnil
。。。所以它可能不会匹配任何东西:DThanks,这肯定比使用
nextAll