Position div next to element

J

johkar

I want to position an absolutely positioned div 75px above the button
clicked on. The following is what I have so far, but as you can tell
it needs more work. I want it positioned in relationship to the button
within the window, not the entire screen...and scrolling the window
shouldn't effect it. Just need some pointers please.

<script type="text/javascript">
function showEmployee(elm,x,y){
if(document.getElementById('awardDiv')){
var myElm=document.getElementById('awardDiv');
myElm.style.display='block';
myElm.style.left=(x - myElm.clientWidth/2) +'px';
myElm.style.top=(y + 25) +'px';
}
}
</script>
<input type="button" name="myButton" value="Select Another Employee"
onclick="showEmployee(this,event.clientX,event.clientY)">
 
P

petermichaux

johkar said:
I want to position an absolutely positioned div 75px above the button
clicked on. The following is what I have so far, but as you can tell
it needs more work. I want it positioned in relationship to the button
within the window, not the entire screen...and scrolling the window
shouldn't effect it. Just need some pointers please.

<script type="text/javascript">
function showEmployee(elm,x,y){
if(document.getElementById('awardDiv')){
var myElm=document.getElementById('awardDiv');
myElm.style.display='block';
myElm.style.left=(x - myElm.clientWidth/2) +'px';
myElm.style.top=(y + 25) +'px';
}
}
</script>
<input type="button" name="myButton" value="Select Another Employee"
onclick="showEmployee(this,event.clientX,event.clientY)">

Where is awardDiv? Does it have styles applied from a stylesheet?

Have you tried the positioning in an HTML document that does not use
JavaScript so that you can get the CSS would like to implement with
JavaScript correct first?

Peter
 
J

johkar

Where is awardDiv? Does it have styles applied from a stylesheet?

Have you tried the positioning in an HTML document that does not use
JavaScript so that you can get the CSS would like to implement with
JavaScript correct first?

Peter

Thanks for the reply. I actually realized from another post that I
needed to put a relative positioned div around my absolute positioned
div and then I didn't need to worry about the x and y position onclick.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,535
Members
45,007
Latest member
obedient dusk

Latest Threads

Top