S
spivee
I'm having an odd type of issue. I want to be able to pass an element
name in my javascript event and find the location of the element, be it
a div, span, img whatever, specifically the top and left attributes.
I have defined my element like so...
### .css file...
#mydiv {
position:absolute;
top:100px;
left:100px;
}
### .html file...
<div id="mydiv" ><a href="#" onMouseUp="myAction()">Some
Content</a></div>
<div id="test"></div>
### and in my .js file I call to test the position..
var divstyle = document.getElementById("mydiv").style;
var left = divstyle.left;
var top = divstyle.top;
document.getElementById("test").innerHTML += "<BR>left="+left;
document.getElementById("test").innerHTML += "<BR>top="+top;
If I do this, left and top show as undefined. If I change up the html
to call a style tag directly, like this..
<div id="mydiv" style="top:100px;left:100px;">....
Then it works just fine. I'm not sure I'm understanding why these two
css definitions are responding differently. I'd rather not have to
define the location of all my elements directly in the html, preferring
to rely on definitions in my css files.
Am I missing something? Is there an alternate way of finding an
elements position?
name in my javascript event and find the location of the element, be it
a div, span, img whatever, specifically the top and left attributes.
I have defined my element like so...
### .css file...
#mydiv {
position:absolute;
top:100px;
left:100px;
}
### .html file...
<div id="mydiv" ><a href="#" onMouseUp="myAction()">Some
Content</a></div>
<div id="test"></div>
### and in my .js file I call to test the position..
var divstyle = document.getElementById("mydiv").style;
var left = divstyle.left;
var top = divstyle.top;
document.getElementById("test").innerHTML += "<BR>left="+left;
document.getElementById("test").innerHTML += "<BR>top="+top;
If I do this, left and top show as undefined. If I change up the html
to call a style tag directly, like this..
<div id="mydiv" style="top:100px;left:100px;">....
Then it works just fine. I'm not sure I'm understanding why these two
css definitions are responding differently. I'd rather not have to
define the location of all my elements directly in the html, preferring
to rely on definitions in my css files.
Am I missing something? Is there an alternate way of finding an
elements position?