firstImgAfterElem2.js

/*reference:http://stackoverflow.com/questions/22920867/how-to-get-the-next-image-tag-after-specific-dom-tag-sibling-or-not*/

by guest271314

HTML

<div>
    <h1>heading</h1>
</div>
<div></div>
<!-- comment `img` `firstsource`, below, for test-case -->
<img src="firstsource" />
<div>
    <div> <span>
            <img src="secondsource"/>
       </span>

    </div>
</div>

JavaScript

/* reference:http://stackoverflow.com/questions/22920867/how-to-get-the-next-image-tag-after-specific-dom-tag-sibling-or-not */

var img = $("h1 ~ img, h1 ~ * img, *:has(h1) + * + img, *:has(h1) ~ * img").attr("src");

$("body").append(img);