Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/grails/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用jquery在匹配连续div中添加类_Jquery - Fatal编程技术网

使用jquery在匹配连续div中添加类

使用jquery在匹配连续div中添加类,jquery,Jquery,我必须在div match上添加cass。我使用了jquerynextAll,但即使没有在匹配div后面,它也会高亮显示。最后一个带有文本“a”的div不应该是nextAll的一部分 $('a')。单击(函数(){ $(this.parent().nextAll('.abc').addClass('active')) }) .active{color:red} 点击 abc abc xyz A. 使用.nextUntil()和:not(): 演示:如果要对文本进行筛选,请使用包含的内容。您的

我必须在div match上添加cass。我使用了jquery
nextAll
,但即使没有在匹配div后面,它也会高亮显示。最后一个带有文本
“a”
的div不应该是nextAll的一部分

$('a')。单击(函数(){
$(this.parent().nextAll('.abc').addClass('active'))
})
.active{color:red}

点击
abc
abc
xyz
A.
使用
.nextUntil()
:not()


演示:

如果要对文本进行筛选,请使用
包含的内容。您的代码使用abc类选择all

$('a')。单击(函数(){
$(this.parent().nextAll(':contains(“abc”)).addClass('active'))
})
.active{color:red}

点击
abc
abc
xyz
A.
$('a').click(function() {
    $(this).parent().nextUntil(':not(.abc)').addClass('active')
})