tags:

views:

60

answers:

1

Hi,

I have some DIV's in my HTML that I load dynamically using AJAX.

$("#workPanel").load("ex.html");

I also have some static links that onclick, call the JQUery masonry to shuffle these dynamic DIV's..

            $('#filtering-nav li.1 a, li.2 a, li.3 a').click(function(){
               $('#primary').masonry();

                 return false;
              });

$('#primary').masonry({
            columnWidth: 100, 
            itemSelector: '.box:not(.invis)',
            animate: true,
            animationOptions: {
            duration: speed,
            queue: false
            }
        });

The shuffling works fine after the first time the page loads, but when the dynamic DIV's are updated, the shuffling does not work anymore. I am guessing the live() or bind() function needs to be called somewhere, but I don't know how and where the binding needs to be done. Please help me out here.

Thanks in advance!

A: 

I think this is what you're after:

To run masonry again you need to shuffle once the .load() completes, you can do this by running it as the callback function, like this:

$("#workPanel").load("ex.html", function() {
  $('#primary').masonry();
});
Nick Craver
Thank you very much for your answer. I do not want to run masonry once load completes. I want masonry to run when the link is clicked again. It seems the dynamic DIV is not getting bound to the DOM after the ajax call and masonry does not run.
I hope I am clear enough, what I mean is that masonry recognizes the DIV the first time the page loads. As you see in the code, I run masonry once certain links are clicked, not when the DIV loads. Now, when the DIV is dynamically updated, and the link is clicked again masonry not seem to run since the DOM is updated and is not bound. By the way, #workPanel is a container DIV that has another DIV #primary that is updated with AJAX. On click of the links, masonry is called on #primary.Thanks!