Link to home
Start Free TrialLog in
Avatar of REA_ANDREW
REA_ANDREWFlag for United Kingdom of Great Britain and Northern Ireland

asked on

onmouseup is not firing

hi,

Can anyone tell me why the onmouseup is not firing when I dpress the mouse button, drag it, it will not fire the onmouseup event. here is my code

    window.onload=function()
    {
                //Apply all the events
           document.onmousemove = function(e){MouseCo(e);}
        for(i=0;i<document.getElementsByTagName('DIV').length;i++)
        {
             document.getElementsByTagName('Div')[i].onmousedown = function(e){MoveElement(e);}
             document.getElementsByTagName('Div')[i].onmouseup = function(){alert("hello");}

        }
    }
   
    function MoveElement(e)
    {
       e = e || window.event;
          DT = e.target || e.srcElement;
    }
Avatar of Zvonko
Zvonko
Flag of North Macedonia image

Check this:

    window.onload=function(){
              //Apply all the events
        document.onmousemove = function(e){MouseCo(e);}
        var div = document.getElementsByTagName('DIV');
        for(i=0;i<div.length;i++) {
            div[i].onmousedown = MoveElement;
            div[i].onmouseup = function(){alert("hello");}
            div[i].onmouseout = function(){this.onmouseup()};
        }
    }
 
    function MoveElement(){
         DT = this;
    }  


Avatar of REA_ANDREW

ASKER

Zvonko, thank you for this. I have amended, and it fires on every mouseout

    window.onload=function(){
              //Apply all the events
        document.onmousemove = function(e){MouseCo(e);}
        var div = document.getElementsByTagName('DIV');
        for(i=0;i<div.length;i++) {
            div[i].onmousedown = MoveElement;
            div[i].onmouseup = MouseUp;
            //div[i].onmouseout = function(){this.onmouseup()};
        }
    }
 
    function MoveElement(){
         DT = this;
    }
    function MouseUp()
    {
          alert(this.id);
    }
how can I stop this? I will be dragging the element, so effectively it will not be a mouseout until they mouseup is fired so should that sort it any way?
Handle the onMouseUp in the document scope.

Zvonko thanks thats great, I am posting a second question now on dragging.

Cheers again

Andrew
Oh, you are welcome.
ASKER CERTIFIED SOLUTION
Avatar of Zvonko
Zvonko
Flag of North Macedonia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Sorry I gorgot to accept. Cheers again