All answers here look fine, but you can do it in reverse order:
$('a:has(.size-thumbnail)').attr("target","_blank");
you can do this because nested anchor tags are not valid;) so the image is always a child of the anchor, not multiple anchors.
source share