/    Sign up×
Community /Pin to ProfileBookmark

offsetTop on tables

Code at the bottom…

As far as I understood it, offsetTop is the distance in pixels from the top of the web browser window to to beginning of an element. But in the case below, it doesn’t work.
Howcome?

// Michelle

<script>
function testa(num) {
var tableId = “t”+num;
document.getElementById(‘MenuLayer’).style.top = document.getElementById(tableId).offsetTop;
}
</script>

</head>

<body>

<a href=”#” onClick=”testa(3)”>test</a><br>
<table width=”300″ cellspacing=”0″ cellpadding=”0″ border=”1″>
<tr>
<td>dsfg</td>
</tr>
<tr>
<td>dsfg</td>
</tr>
<tr>
<td id=t3>dsg</td>
</tr>
</table>

<div id=”MenuLayer” style=”position:absolute; background-color:gray; layer-background-color:gray; visibility:visible;”>
bla bla bla
</div>

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@michelleauthorJun 24.2003 — How can I do this?

How would I go about constructing a function that count downwards from the chosen object?

function getRealOffsetTop(objName) {

// loop until no parent is available

// Add the offset of this to the sum of all offsets

}
Copy linkTweet thisAlerts:
@michelleauthorJun 24.2003 — OK... now I get it. I thought I was supposed to look in dumpObject.js..

Thanks!

// Michelle
×

Success!

Help @michelle spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...