Script are executed in the order of appearance in the document. The contents of a script tag are evaluated on encounter, so, the last <script>
element is always the current one.
Code:
<div>
<script>
var scriptTag = document.getElementsByTagName('script');
scriptTag = scriptTag[scriptTag.length - 1];
var parent = scriptTag.parentNode;
</script>
</div>