Skip to main content
Home / The Lodge / Building a Mobile-First WordPress-Powered Artists Website / #034 – Ajaxing in a Blog Post

#034 – Ajaxing in a Blog Post

We end up with a really simple test which loads in an article from the blog to display if there is room:

// Load additional content if enough room
enquire
  .register("(min-width: 700px)", {
    match: function() {
      $("#home-article").load("/blog/ #main-article");
    }
  })
  .listen();

jQuery makes Ajax super easy, and even easier with the .load() function. The only little trick here is where we've added #main-article to the end up the URL which limits what it injects onto the page to that CSS selector. It would be more perfect if we engineered some solution to only return the content we need to add, but this is a such a quick and easy solution it's kind of beautiful.

Sorry about the not-great sound on this one =(.

icon-link icon-logo-star icon-search icon-star