I'm trying to create a masonry display with generated div blocks. The strutcture is the following :
<div id="grid" class="panel">
  <div id="grid">
    <div id="posts">
      
      <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
      <script src="https://cdnjs.cloudflare.com/ajax/libs/masonry/3.3.2/masonry.pkgd.js"></script>
      <script src="assets/js/masonry.js"></script>
      
      <div class="post"> <!-- The .post are generated dynamically -->
        <!-- Block content generated dynamically -->
      </div>
   <div class="post"> <!-- The .post are generated dynamically -->
        <!-- Block content generated dynamically  -->
      </div>
    </div>
  </div>
</divAnd the jQuery :
jQuery(window).load(function () {
 // Takes the gutter width from the bottom margin of .post
 var gutter = parseInt(jQuery('.post').css('marginBottom'));
 var container = jQuery('#posts');
 // Creates an instance of Masonry on #posts
 container.masonry({
  gutter: gutter,
  itemSelector: '.post',
  columnWidth: '.post'
 });
    /*
     * some code
     */
});Each time the page is loading, I get the error : Uncaught TypeError: container.masonry is not a function. I'm newbie in jQuery, and that's why I use a masonry template from here
I have already looked at some posts as : Event binding on dynamically created elements? But I couldn't figure out how to solve my problem. I suppose the error occurs because I'm trying to bind events to elements which aren't created yet.
 
     
    