Kars Barendrecht
Kars Barendrecht

Reputation: 549

Why is JQuery .empty() not working?

! function(a) {
 $("#videos","#uploads","#tijdlijn","#profel").empty(); 
a.fn.fbAlbum = function(l) {
      var t = this,
        e = {
            albumID: 0x240fa56a571e02,
            limit: 30,
            ulClass: "album",
            callback: "",
            title: !0
        };
    l && a.extend(e, l);
    var i = "https://graph.facebook.com/" + e.albumID + "/photos?limit=" + e.limit + "&access_token=862683673820828|15Gx44NW43LHI92o__bRPA6lz44";
    return a.getJSON(i, function(l) {
        var i = [];
        for (var o in l)
            for (var c in l[o])
                if (val2 = l[o][c], "undefined" != typeof val2.source) {
                    var r = "";
                    e.title && val2.name && (r = val2.name), i.push('<li class="item_box_pic"><a class="imageLink" rel="group" data-featherlight="' + val2.source + '" "href="' + val2.source + '"><img src="' + val2.picture + '" alt="Facebook foto thumbnail, ' + r + '" title="' + r + '"/></a></li>');
                }
        a("<ul />", {
            "class": e.ulClass,
            html: i.join("")
        }).appendTo(t), e.callback && e.callback();
    }), this;
};
}(jQuery);

this script is loaded on click, so it loads a set of images from facebook after a button is clicked. (example: http://sophiadeboer.nl/#media)

The problem is that when there is clicked again, the content appends, how come it doesn't dissapear because of the

 $("#videos","#uploads","#tijdlijn","#profel").empty(); 

Could somebody explain my error?

Upvotes: 1

Views: 2392

Answers (2)

ArcangelZith
ArcangelZith

Reputation: 101

Put the function inside plugin function call

Pass the selection set in the first parameter, no quotes

a.fn.fbAlbum = function(l) {
    $("#videos,#uploads,#tijdlijn,#profel").empty();
    ...

Upvotes: 2

charlietfl
charlietfl

Reputation: 171669

Your call to empty() is outside the function and the formatting is incorrect for the selector. Selector should be one string ...not numerous arrguments

Put it inside so it gets called each time the function is called

a.fn.fbAlbum = function(l) {
   $("#videos, #uploads, #tijdlijn, #profel").empty(); 

   .....
}

Upvotes: 2

Related Questions