| ChrisRickard on Oct 20, 2004 at 4:39:26 PM (# 1) Well to get the ID of the parent you first need a reference to the element that generated the event. Then loop up using the parentNode property until you find the right element. You can use its id property from there.
The ways of getting the top and left coordinates of the element for IE and Moz are as such
IE: element.getBoundingClientRect()
Mozilla: document.getBoxObjectFor() (I don't know why the hell Mozilla's DOM reference doesn't list this! It took me forever to find the method name because I thought it was document.getBoxModelFor)
hedger on Oct 20, 2004 at 7:32:26 PM (# 2) This message has been edited.Oh thanks God and dear ChrisRickard .
document.getBoxObjectFor() is exactlly what I need.
Where did you learn that?
here is the general solution
function getPos(el) { var x,w,y,h; if (document.getBoxObjectFor) { var bo = document.getBoxObjectFor(el); x = bo.x; w = bo.width; y = bo.y; h = bo.height; } else if (el.getBoundingClientRect) { var rect = el.getBoundingClientRect(); x = rect.left; w = rect.right - rect.left; y = rect.top; h = rect.bottom - rect.top; }
el.x = x; el.y=y; el.w= w; el.h = h; alert("Left: " + x + "\rTop: " + y + "\rWidth: " + w + "\rHeight: " + h); }
hedger on Oct 20, 2004 at 11:35:29 PM (# 3)Google give you only : Results 1 - 6 of about 11 for document.getBoxObjectFor. (0.28 seconds)
only 6 results, ChrisRickard , did you get that by luck?(hehe)
ChrisRickard on Oct 21, 2004 at 8:10:20 AM (# 4)I think I got it from poking around WebFx, but I'm not sure. It's certainly too important to be such an obscure method. I don't know why nobody ever mentions it... hedger on Oct 21, 2004 at 8:48:52 AM (# 5)One main reason may be that this is not a stabdard DOM method. But for XUL, it is. http://softwant.com/cgi-bin/kimsboard/mozilla/xultu/elemref/ref_XULElement.html
Here is the related article:
Type: nsIBoxObject
This property is available for elements that are derived from boxes, which is most displayable XUL elements. You can retrieve the boxObject for non-XUL elements using the document.getBoxObjectFor method. The boxObject contains a number of properties, described below.
Note that it also provide some interesting methods, such as getElementsByAttribute ( attrib , value )
He, he. We do have more to learn.
scwilson on Oct 22, 2004 at 5:56:47 AM (# 6) This message has been edited.Thanks to ChrisRickard and hedger for all the help; glad also to see that the topic also useful to others
Steve (scwilson)
|