0

我试图让评论在带有 jquery 的 wordpress 滑块中工作。我绝不是专家,所以我正在寻求帮助。这是我到目前为止所拥有的。

<div id="slider-1>
<div id="content-805">content here</div>
<div id="comments-wrap-805" class="comments-805"> //Parent
<div id="commentform-798" class="comments-798">comment stuff</div> //child
<div id="commentform-605" class="comments-605">comment stuff</div> //child
<div id="commentform-735" class="comments-735">comment stuff</div> //child
<div id="commentform-425" class="comments-425">comment stuff</div> //child
<div id="commentform-810" class="comments-810">comment stuff</div> //child
</div>
</div>

id 和 classes 后面的数字是 wordpress post id。我想要做的是隐藏没有与父母匹配的班级的孩子。这可能吗?

到目前为止,这是我的脚本..

jQuery(document).ready(function() {
if ((" " + jQuery("div[id^='commentform']").parent().attr('class') + " ").match(/\scomments-\d+\s/) != null) {
jQuery(this).hide();
}
});

干杯

4

1 回答 1

0

你可以这样做

$.each($("div[id^='comments-wrap']"),function(){ // this will fetch all parent div's
    var CurrectDiv=$(this);
    CurrectDiv.find('div').filter(function(){
        if($(this).attr('class')==CurrectDiv.attr('class'))
        {
           $(this).hide(); 
        }
     });
});

​工作演示

于 2012-11-17T12:38:25.993 回答