I call this function with two elements having the same parentNode
:
var test = function(target, div){
alert(div.parentNode == target.parentNode ); // gives true
alert(div.offsetParent == target.offsetParent); // gives true
div.setAttribute("style", "position:relative; float:left; height:" + target.offsetHeight + "px;");
alert(div.parentNode == target.parentNode); // gives true
alert(div.offsetParent == target.offsetParent); // gives false!!!
}
As you can see that both elements have same parent, which means they are inside same branch of the DOM tree, how come they have different offsetParent
?
I notice here that div has relative position, which seems to be the reason because when I remove it both alerts give true. (but normally the position of an element should not affect its offsetParent
)
/* I have edited the function after some more invistigation it should show more where lies the problem */ I got the same results on FF and Chrome. parentNode of both elements is a table-td
Thank you for answering.