Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/81.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 找到同级后将类添加到同级_Jquery - Fatal编程技术网

Jquery 找到同级后将类添加到同级

Jquery 找到同级后将类添加到同级,jquery,Jquery,如果我使用以下语句 if ($('divA').siblings().text() == "1") { the code here needs to add a class to that specific sibling where text = 1 } 如何选择要添加类的同级div $('divA').siblings().filter(function(index) { return $(this).text() == "1"; }).addClass('yourClass'

如果我使用以下语句

if ($('divA').siblings().text() == "1") {
 the code here needs to add a class to that specific sibling where text = 1
}
如何选择要添加类的同级div

$('divA').siblings().filter(function(index) {
    return $(this).text() == "1";
 }).addClass('yourClass');
您可以使用该函数将
.sibles()
集合减少为仅针对您的条件返回true的集合,然后使用
.addClass()
将您的类添加到筛选的同级