gl**@tollnz.co.nz wrote:
Hi Guys,
I am having problem finding the position of a button that I can set the
div position next to the button.
Not to nit-pick, but what do you mean by 'position'?
Do you want to place the div using HTML/DOM rendering or absolute
co-ordinates (like a tool-tip)?
For HTML/DOM rendering, you can create a div and append it to anther
element similarly to if you'd coded it in the original HTML - or you
could code it in the HTML and have it hidden, then use script to
reveal it when a button is clicked.
If you are looking for a tool-tip kind of thing, you may be after the
coordinates of a mouse click.
Alternatively, you can get the location of the top left corner of the
button reasonably easily, but lower right is more difficult.
Here's finding the location of a mouse click (Firefox & IE):
<script type="text/javascript">
function sayPos(e){
e = e || window.event;
alert('X: ' + e.clientX + '\nY: ' + e.clientY);
}
</script>
<div id="divA" style="position:relative; height:100px;
border:1px solid red;"
onclick="sayPos(event);"></div>
Test thoroughly as the support for this stuff varies greatly across
different browsers.
More info? Tooltips:
<URL:http://www.walterzorn.com/tooltip/tooltip_e.htm>
Finding the coordinates of an element on a page (and lots of other
useful stuff about CSS/JavaScript/DOM/browser compatibility):
<URL:http://www.quirksmode.org/js/findpos.html>
--
Rob