开发者

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.


Use $.each to loop through your selected comments.


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.
    }
};
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜