Skip to content

Instantly share code, notes, and snippets.

@ericmann
Last active December 16, 2015 07:19
Show Gist options
  • Save ericmann/5397940 to your computer and use it in GitHub Desktop.
Save ericmann/5397940 to your computer and use it in GitHub Desktop.
// load posts
var loadPosts = document.getElementById( 'loadposts' ),
$loadPostsA = $( loadPosts.querySelectorAll( 'a' ) ),
$articles = $( document.getElementById( 'articles' ) );
$loadPostsA.on( 'click', function(e) {
e.preventDefault();
var $this = $( this );
$this.html( 'Loading…' );
$.ajax({
type: "GET",
url: $this.attr( 'href' ) + '#content',
dataType: "html",
success: function( out ) {
var $out = $( out ),
respElement = $out[0],
$result = respElement.querySelector( '#content article' ),
nextLink = respElement.querySelector( '#loadposts a' ).getAttribute( 'href' );
$articles.append( $result );
$this.text( 'Load More' );
if ( nextlink != undefined ) {
$this.attr( 'href', nextlink );
} else {
loadPosts.remove();
}
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment