// store the links parent selectors as variables var $next = $(".next"); var $prev = $(".prev"); // if the prev posts link doesn't exist but the next link does if ($prev.children().length == 0 && $next.children().length > 0) { // add a span with prev $prev.append('Prev'); // if the next posts link doesn't exist but the prev one does } else if ($next.children().length == 0 && $prev.children().length > 0) { // add a span with next $next.append('Next'); };