jQuery click event not working when mouse moves from one div to another with button held down

Posted by Acorn on Stack Overflow See other posts from Stack Overflow or by Acorn
Published on 2010-04-25T17:45:44Z Indexed on 2010/04/25 17:53 UTC
Read the original article Hit count: 243

Filed under:
|
|
|

I've made a page that uses jQuery to allow you to place <div>s on the page based on your mouse coordinates when you click.

The page

And here's the javascript:

$('document').ready(function() {
    $("#canvas").click(function(e){
    var x = e.pageX - this.offsetLeft;
    var y = e.pageY - this.offsetTop;
    $(document.createElement('div')).css({'left':x + 'px', 'top':y + 'px'}).addClass('tile').appendTo('#canvas');
    });
});

I've found that if you mousedown in the div#canvas and mouseup with your pointer over a placed <div> (or vice versa) then a new <div> doesn't get placed. Why is this?

© Stack Overflow or respective owner

Related posts about jQuery

Related posts about JavaScript