faqts : Computers : Programming : Languages : JavaScript : Images

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

12 of 14 people (86%) answered Yes
Recently 9 of 10 people (90%) answered Yes

Entry

In IE, how to find the absolute (x,y) of an image that may be nested within one or more tables (or other containers)?

Jan 5th, 2006 02:37
Trung Ha Pham, Anthony Howe,


Author: don't remember :(
<html>
<body>
<script>
function getOffsetLeft (el) {
var ol = el.offsetLeft;
 while ((el = el.offsetParent) != null)
 ol += el.offsetLeft;
 return ol;
}
function getOffsetTop (el) {
 var ot = el.offsetTop;
 while((el = el.offsetParent) != null)
 ot += el.offsetTop;
 return ot;
}
function showXY(image){
 var x = getOffsetLeft(image);
 var y = getOffsetTop(image);
 alert(x+' , '+y);
}
</script>
<table border="1" width="130">
	<tr>
		<td>
		click on image 
		<table border="1" width="100%" cellspacing="5">
			<tr>
				<td><img src="http://www.faqts.com/images/javascript-faqts.gif" 
onclick="showXY(this)"></td>
			</tr>
		</table>
		</td>
	</tr>
	<tr>
	<td>
	 <img src="http://www.faqts.com/images/javascript-faqts.gif" 
onclick="showXY(this)">
	</td>
	</tr>
</table>
</body>
</html>