2013-03-13 113 views
0

我有两列,其中一列包含类“parentandsub”的元素。循环比较2列中的元素

我希望通过在A列各parentandsub元素循环,并检查它是否在列B.如果不是的话,那么我想强调在A列中

这里是我的代码元素,但它不工作:

$(".column2 .parentandsub").each(function(){ 

    if ($(".column1 .parentandsub:contains('" + $(this).html() + "')").length == 0) { 
    $(this).wrap('<span class="parentandsubhilite" />'); 
    } 

}); 

谢谢你的任何帮助。

+0

你能提供什么,你目前有[的jsfiddle(http://www.jsfiddle.net)的例子吗?这可能有更好的方法。 – Dom 2013-03-13 16:06:21

回答

0

尝试:

$(".column2 .parentandsub").each(function(index){ 
    if ($(".column1 .parentandsub:nth-child("+(index+1)+"):contains("+$(this).html()+")").length== 0) { 
     $(this).wrap('<span class="parentandsubhilite" />'); 
    } 
});