How do I get the position of a page element

Add-in Express™ Support Service
That's what is more important than anything else

How do I get the position of a page element
Claus Topholt

Posts: 1
Joined: 2019-12-09
I have an onClick handler for a context menu, so users can right-click any page element. Now I'd like to get the position of the element. It seems I can get the size (clientWidth and clientHeight) but how do I get the position on the page?

Edit: Figured it out:

var element = (IHTMLElement)htmlElement;
var x = 0;
var y = 0;

while(element.parentElement != null)
	x += element.offsetLeft;
	y += element.offsetTop;
	element = element.parentElement;
Posted 09 Dec, 2019 10:14:05 Top
Andrei Smolin

Add-in Express team

Posts: 18943
Joined: 2006-05-11
Hello Claus,

Thank you for posting your solution!

Andrei Smolin
Add-in Express Team Leader
Posted 10 Dec, 2019 02:49:40 Top