I have an ASP.NET control that spits out <span> elements and I won't know their Ids until the ASP.NET code is compiled.

I'm trying to solve this problem using Javascript, using the ParentNode property, but so far I've been unsuccessful.

Consider this sample Html/Javascript code:

Code:
<html>
<head>
</head>

<body>

<div id ="mydiv"> some text

	<script type="text/javascript">
	 var data = document.getElementById('div2').getAttribute('id');
	alert(data);

</script>

</div>
</body>

</html>
Essentially I'm trying to capture the id of the <div> element inside of which the javascript code is located, but I won't know its ID before runtime. I tried code such as document.parentNode.getAttribute('id') and this.parentNode.getAttribute('id') but it did not work.

Can someone please tell me how to accomplish this?