user969591
user969591

Reputation: 23

JS/JQuery: I Can't get the loop right

$(document).ready(function() {
    $("#main-rss-link").click(function() {
        $("#main-rss-link").toggleClass('on'), $("#subscribe-list").slideToggle();
    });
    var a = $("li.comment").attr("id");
    var b = $("li.comment[id='" + a + "']");
    var c = $("li.comment > div.comment-body div > p > a").attr("href");
    if ($.each('#' + a == c)) {
        var d = $("li.comment > div.comment-body div > p > a[href='" + c + "']");
        var e = document.createElement("ul");
        $(e).addClass("children").appendTo(b);
        d.parents("li").appendTo(e);
        $("li ul li div.reply").remove();
    };
});

I want it to loop through all of my comments, but it only affects the first one it finds.

Upvotes: 1

Views: 78

Answers (2)

Jason Gennaro
Jason Gennaro

Reputation: 34855

I added the $.each(), but it still isn't working. I updated the problem with $.each() inserted to where I believe it was to go.

Do this

$('#' + a).each(function(){  //loop through each a variable 
    if(a == c){              //then, if a is equal to c, do the following
       var d = $("li.comment > div.comment-body div > p > a[href='" + c + "']");
       ....
       ///continue with the rest of the code etc.
    }
};

Upvotes: 0

aziz punjani
aziz punjani

Reputation: 25776

Use $.each to loop through your selected comments.

Upvotes: 3

Related Questions