Search code examples
jqueryeventslivefacebox

Facebox plugin is not removing previous content when used with live


I am using facebox in the content that I have loaded with ajax

Normally, the plugin removes previous content, so clicking multiple times on the same link would still show the one image.

But not used with live. It will stack up the images

Setting it to empty below will not work??It already does that in the plugin also?

$('a[rel*=facebox]').live("mousedown", function() { 

if( $('#facebox .content div').length > 0 ) $('#facebox .content div').empty(); 
a = $('#facebox .content div').length;
$('#counter').html(a);

    $(this).facebox(); 

});

(The div length actually says 0 , but still shows the full stack)

How could I make this work with live?

thanks, Richard


Solution

  • Try emptying the contents of the facebox by binding to its beforeReveal hook:

    $(document).bind('beforeReveal.facebox', function() {
        $("#facebox .content").empty();
    });