I used @kaverzniy answer, but wrapped it in
var container = $('#container');
if(container.masonry()) {
$('#masonry').masonry( 'destroy' );
}
to avoid calling methods on the masonry before initialization (if it has not yet been initialized).
source
share