0

i want the div to be displayed where the mouse was clicked... whats wrong?

<head>
<style type="text/css">
#layer1 {
   position:fixed;
display: none;
   width:600px;
   height:auto;

}
</style>
</head>

<body>
<input type="button" value="Button 3"
onclick="setVisible();">

<textarea id="reply" name="reply">testing12345678910ffafaf</textarea>
<div id="layer1"></div>
<script type='text/javascript'>

function setVisible() {

var div = document.getElementById('layer1');
// put the correct content in the div here
div.innerHTML = document.getElementById('reply').value;
div.style.left = window.event.clientX + 'px';
div.style.top = window.event.clientY + 'px';

div.style.display = 'visible';}
</script>

</body>
2
Contributors
1
Reply
2
Views
7 Years
Discussion Span
Last Post by alipica
0

Firstly, display needs to be set to 'block' not 'visible' in your js.

Also, the javascript didn't work for me until I removed:
div.style.left = window.event.clientX + 'px';
div.style.top = window.event.clientY + 'px';

You should try assigning the client X and Y to their own variables and then refer to the variables in those two lines. Let me know if that works!

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.