One possible approach:
$('.vertical').filter(function() {
var $this = $(this);
if (!
( $this.next().is('.vertical') || $this.prev().is('.vertical') )
) {
$this.addClass('solo');
}
});
Demo. Note the change: I've closed all those <figure>
elements (and some others, like <h1>
) as, unlike <p>
, they do require the closing tag.