Your problem is down to when you're doing things (not what you're doing). So, you want to achieve this: Make an ajax call to Facebook to grab some images Append the new markup from Facebook to your DOM Call the gridify function to arrange the markup added to your page...