2012-11-17 36 views
0

我想获得与jQuery的WordPress的滑块工作的意见。我不是专家,所以我要求一些帮助。这是迄今为止我所拥有的。jQuery的匹配独特的类名

<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和class后面的数字是WordPress的发帖ID。我想要做的是隐藏没有与父母相匹配的班级的孩子。这可能吗?

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

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

干杯

回答

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(); 
     } 
    }); 
}); 

​ Working Demo

+0

@拉胡尔。非常感谢,这完美的工作! – user1813098