You need to untie the mousemove handler that is still currently attached, for example:
function setPos(e) { //can be $('#box') in this case... $(this).parent('#box').css({ cursor: 'move', top: e.pageY - 15, left: e.pageX - 125 }); } $('.box-title').live('mousedown click', function(e) { if(e.type == 'mousedown') { $(window).mousemove(setPos); } else if(e.type == 'click') { $(window).unbind('mousemove', setPos); } });
Or, in jQuery 1.4.3+, the .live() handler might be a little cleaner:
$('.box-title').live({ mousedown: function() { $(window).mousemove(setPos); }, click: function() { $(window).unbind('mousemove', setPos); } });
Aside, it seems you have a few id="box" elements on the page ... make sure you use the classes in these cases, in this code $(this).parent('#box') will be $(this).closest('.box') .
source share