View Full Version : onmouseup event in NS 6

04-25-2003, 06:28 PM
This is a NS6 related question. I drag a div and drop it on a table row. When I drop the div I want to find out which row I drop that div on.

How do I do that ? Right now with my code'onmouseup' event always returns the id of the div instead of id of the row I dropped on.

Please take a look at the code. You can copy it and test it too if you want.

Your help will be greatly appreciated.


.dragDiv {position: absolute;}
#dragOne {border: 1px solid gray;}
var dragElement;

function getDraggableElement (target) {
if (target.className == 'dragDiv')
return target;
while ((target = target.parentNode));
return null;

function dragStart (e) {
dragElement = getDraggableElement (e.target);
if (dragElement) {
document.onmousemove = dragOn;
document.onmouseup = dragEnd;

function dragOn (e) {
dragElement.style.left = e.clientX + 'px';
dragElement.style.top = e.clientY + 'px';

function dragEnd (evt) {
document.onmousemove = null;
document.onmouseup = null;
dragElement = null;

document.onmousedown = dragStart;

<div id="dragOne" class="dragDiv">This is the dragable text</div>

<table id="tableOne" align="center" border="2">
<tr id="rowOne">
<td width="200"><div> Row One </div></td>

<tr id="rowTwo">
<td width="200"><div> Row Two </div></td>

Roy Sinclair
04-25-2003, 09:32 PM
Try setting up a global onmousemove event handler, one of the items in the event object should always be what element the mouse is currently over, if you jsut store that in a global variable in the event handler it should point to the drop item when the onmouseup event occurs.

04-26-2003, 12:13 AM
I am not sure if I understand you right.
I moved the document.onmouseup outside the dragStart function. But still it dosen't seem to work.

I also tried to assign it to a global variable.
var mouseUpVar = document.onmouseup
And I was alerting mouseUpVar in the dragEnd method. But that dosen't work either.

Can you pls give me an example ?


04-28-2003, 05:09 AM
PLEASE !! someone help me on this. It's pretty urgent.