Is there something wrong with this code?

For some reason, the class 'continue' is not 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>title</p>
     <a href="link">Continue</a>
</div>
+3
source share
2 answers

You have to call .addClassfor an object, otherwise what would it add a class?

$(this).addClass('continue');
+1
source

You can call:

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

Or:

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

All Articles