<div id="d1">
<script>
var tags = document.getElementsByTagName('script');
alert( tags[ tags.length - 1 ].parentNode.id );
</script>
</div>
<div id="d2">
<script>
var tags = document.getElementsByTagName('script');
alert( tags[ tags.length - 1 ].parentNode.id );
</script>
</div>