-
Notifications
You must be signed in to change notification settings - Fork 2.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Appending via AJAX and using jQuery #374
Comments
Hi Drew! Thanks for the reduced test case! It helps a lot. Given that example, the problem is that jQuery is able to append a string of HTML. Whereas, Masonry's Here's your example, simplified a little. Instead of AJAXing content, it just appends the string of HTML: var moreBlocks = '<div class="block large">6</div><div class="block large">7</div><div class="block large">8</div>';
// Get some more blocks
$('#more').click(function(){
// Append new blocks
$container.append( moreBlocks );
// Have Masonry position new blocks
$container.masonry( 'appended', moreBlocks );
}); The solution is to wrap up the string of HTML in a jQuery object and use that for appending. See http://codepen.io/desandro/pen/euGdB $('#more').click(function(){
// make jQuery object from HTML string
var $moreBlocks = $( moreBlocks );
// Append new blocks
$container.append( $moreBlocks );
// Have Masonry position new blocks
$container.masonry( 'appended', $moreBlocks );
}); Seems like a lot of people are having trouble with appended on Stack Overflow, but I don't know if it's related to this problem. |
Hey David, Thanks for this! But running you code in a .get() callback gives the "TypeError: t[a] is not a function" error, whereas running it as a var works fine. This doesn't work:
But if you switch out the get(data) with a var data = "html" (as per your code pen) it works fine. So why is that? What's with the .get() data variable that Masonry doesn't like it? |
Thanks!!! |
Just wanted to say thanks for this 👍 |
Yes, thank you very much for explaining this! |
Hello, I just want to say that I had this problem on v3.1.2 and I solved using the You should mention this in the documentation. |
@josemarluedke Do you have a live URL I can take look at? I'm not able to reproduce the error given this example: http://codepen.io/desandro/pen/evLkD |
closing as fixed. |
Thanks |
Why this does not work now? Loaded blocks do not match. |
Big time fan of your work. I use it all the time.
I've been trying to get my head around the new Masonry. I'd like to stick to a jQuery way of appending new bricks to an existing Masonry instance.
I've followed the Docs as close as I can, and I'm getting a "TypeError: t[a] is not a function" error when trying to use the 'appended' method.
Here is a link to my reduced test case:
http://labs.funkhausdesign.com/examples/masonry/appended.html
But my guess is there is something wrong with this code:
Once I have this solved, I will leave up my example page and go through Stackoverflow and answer a lot of these questions people are having:
http://stackoverflow.com/search?q=masonry+appended
The text was updated successfully, but these errors were encountered: