为nextAll使用字符串选择器

jQuery Use a string selector for nextAll

本文关键字:字符串 选择器 nextAll      更新时间:2023-09-26

我一直在努力编写nextAll的字符串选择器表示,就像这样。

$('span:nextall(span.simple)');

而不是

$('span').nextAll('span.simple');

可以扩展jQuery表达式":"来做这个吗?

不是很优雅但是

https://jsfiddle.net/bdellinger/ejrvjn4h/2/

$( "span.third" ).nextAll().css( "color", "red" );

$( "span:gt("+$( "span" ).index( $('.third'))+")" ).css( "color", "red" );

我找到了一个更简单的解决方案,那就是使用同胞选择器。

$('span ~ span.simple');