Вопрос

I'm trying to get comments working in a slider for wordpress with jquery. I'm not an expert by no means so i'm asking for some help. Here's what I have so far.

<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>

The numbers after the id's and classes are the wordpress post id. What i'm trying to do is hide the child that doesn't have a class that matches the parents. Is this possible?

Here's my script so far..

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

Cheers

Это было полезно?

Решение

you can do it like this

$.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

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top