I am trying to use the currentStyle object to retrieve the position of a div that is defined in an external style sheet as: #info div { position: absolute; left: 340px; top: 375px; /* position of balloon pop-up */ z-index: 100; } Using: var elemID = 'info'; var elem = document.getElementById(elemID); if (elem.currentStyle) { top = elem.currentStyle.top; left = elem.currentStyle.left; } always returns "auto" and not the pixel positions. Why?
"Chevron7" wrote in message news:30AAB772-FF19-448F-985E-6E4445560855@microsoft.com > I am trying to use the currentStyle object to retrieve the position > of a div that is defined in an external style sheet as: > > #info div { > position: absolute; > left: 340px; > top: 375px; /* position of balloon pop-up */ > z-index: 100; } > > Using: > > var elemID = 'info'; > var elem = document.getElementById(elemID); > if (elem.currentStyle) { > top = elem.currentStyle.top; > left = elem.currentStyle.left; > } > > always returns "auto" and not the pixel positions. Why? "#info div" means "all <div> elements that are descendants (direct or indirect) of an element whose id is 'info' ". It does not mean, as you seem to assume, "an element with an id of 'info' which also happens to be a <div> ". That would have been div#info -- With best wishes, Igor Tandetnik With sufficient thrust, pigs fly just fine. However, this is not necessarily a good idea. It is hard to be sure where they are going to land, and it could be dangerous sitting under them as they fly overhead. -- RFC 1925
Thanks for catching that; I don't know how I overlooked that ... a bit of dyslexia I guess. With that correction the object is now working as it should. "Igor Tandetnik" wrote: > "Chevron7" wrote in message > news:30AAB772-FF19-448F-985E-6E4445560855@microsoft.com > > I am trying to use the currentStyle object to retrieve the position > > of a div that is defined in an external style sheet as: > > > > #info div { > > position: absolute; > > left: 340px; > > top: 375px; /* position of balloon pop-up */ > > z-index: 100; } > > > > Using: > > > > var elemID = 'info'; > > var elem = document.getElementById(elemID); > > if (elem.currentStyle) { > > top = elem.currentStyle.top; > > left = elem.currentStyle.left; > > } > > > > always returns "auto" and not the pixel positions. Why? > > "#info div" means "all <div> elements that are descendants (direct or > indirect) of an element whose id is 'info' ". It does not mean, as you > seem to assume, "an element with an id of 'info' which also happens to > be a <div> ". That would have been div#info > -- > With best wishes, > Igor Tandetnik > > With sufficient thrust, pigs fly just fine. However, this is not > necessarily a good idea. It is hard to be sure where they are going to > land, and it could be dangerous sitting under them as they fly > overhead. -- RFC 1925 > > >