Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Getting the position of a layer 1

Status
Not open for further replies.

adam0101

Programmer
Joined
Jun 25, 2002
Messages
1,952
Location
US
This is driving me nuts!! Why wouldn't the alert box show 130?

<html>
<head>
<style>
#test{position:relative;left:130px;}
</style>
</head>
<body onload=&quot;alert(parseInt(document.getElementById('test').style.left))&quot;>

<div id=&quot;test&quot;></div>

</body>
</html>

Adam
 
Got it,
I used alert(parseInt(document.getElementById('test').offsetLeft))

Adam
 

The 'style' object represents the current settings of all possible inline styles for a given element.
Code:
alert(parseInt(document.styleSheets[0].rules[0].style.left))
Will retrieve the appropriate value. Though if you want to find the rule by name, you'll need to loop through the rules array until you find one where rules.selectorText == '#test'
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top