开发者

Is there something wrong with this code?

For some reason, the 'continue' class isn't getting added (last line).

function getBlogs(element, url, limit, feed){
    jQuery(element).load(url+ ' .xg_blog_list .xg_module_body:lt('+ limit+ ')', function(){
        jQuery(this).prepend("<a class='home-rss' href='"+ feed+ "'></a>");
        jQuery(this).append("<a class='view-all-blogs' href='"+ url+"'>View More &raquo;</a>");
        jQuery(".xg_module_body .postbody").last("a").each(function(index) {
            addClass("continue");
        });
    });
}

Relevant html:

<div class="postbody">
     <p><a href="link"><img src="image"></a></p>
     <p>titl开发者_如何学Pythone</p>
     <a href="link">Continue</a>
</div>


You can either call:

jQuery(".xg_module_body .postbody").last("a").each(function() {
        $(this).addClass("continue");
});

Or:

jQuery(".xg_module_body .postbody").last("a").addClass("continue");


You have to call .addClass on an object, otherwise what would it add the class to?

$(this).addClass('continue');
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜