Q: How to prevent execution of onmousedown and onmouseup of div using javascript? I have a div.
<div id="down" 
onmousedown="mousedown('url(/scanToUserBox/img/cpt_subfunc_005_next_d.png)', this)" 
onmouseup="mouseup('url(/scanToUserBox/img/cpt_subfunc_005_next_i.png)', this)" 
onclick="changePage('down')">
</div>

I want to prevent the execution of the events in some instances. I already tried disabling the div but still the events are executed.

A: Why can't you use JQuery and attach events based on actions? Are you restricted to javascript?
Javascript Example:
document.getElementById('down').addEventListener('mousemove', elementMove, false);

A: Use JQuery, and attach functions to mouseup and mousedown event in which you can execute code depending on conditions:
$("#down").mouseup(function(){
  if(a=b) {

  }
}).mousedown(function(){
  if(b=c) {

  }
});


A: I believe, if you had added your event Handler simply via javascript with something like
var desDiv = document.getElementById('down');
desDiv.addEventListener('mousedown', mymousedownfn, false);

//you could have removed the eventlistener with
desDiv.removeEventListener('mousedown',mymousedownfn,false);

As you have added the eventlistener as an attribute of the div, I think the javascript becomes part of the attribute value as well and you would then need to set it to null to remove it. Something like
var desDiv = document.getElementById('down'); 
destdiv.onmousedown = null; 

You have to figure out when to set the 'destdiv.onmousedown' to null to make it work for you

A: I finally found the solution. It is event.returnValue = false;
