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()
将您的类添加到筛选的同级