The problem is that inside the figure
tag, figcaption
is the last child, not the last a
tag! So the second line of $('#button-next').click
have to be changed from this:
if ($('figure a.oldActive').is('figure a.oldActive:last-child')) {
...to this:
if ($('figure a.oldActive').is('figure a.oldActive:nth-last-child(2)')) {