I am trying to display a node next to another (on top of the content), with Javascript. I cannot change the document structure for this node, and I need to insert the new node under the same parent. I would like to use position:absolute to position the new node, but it seems hard to find the reference node position. Using getBoundingClientRect() on the reference node does not work, because the node might be inside an ancestor with position:relative or position:absolute, and getBoundingClientRect() returns a position relative to the document, which cannot be used as coordinates with CSS position:absolute.
Do I really have to loop through the ancestors to find the first one with position:absolute or position:relative in order to find the CSS absolute position, or is there an easier way to get this information ?
Note: I am looking for an answer in pure Javascript.
Update: In other words, I am looking for the top/left pixel position an element should have to be displayed at the same place when its CSS position is changed to 'absolute'. offsetTop/offsetLeft is not the answer because the element might be inside a table, and in that case offsetParent is the table cell.