[jQuery] Colorize table tds when mouse button is clicked

[jQuery] Colorize table tds when mouse button is clicked


Hi
I have a script to colorize the tds of a table when the left mouse
button is clicked on each td and when after clicking on a td the mouse
button is still pressed and over other tds. The problem is that
sometimes when I keep pressed the mouse button and move the mouse
fast, if I release the button the script continues filling the cells
as if it were still pressed.
I know the script is pretty simple:
var isMousedown = false;
$("#grid td")
.mousedown(function(){
    isMousedown = true;
    setColor($(this));
})
.mouseover(function(){
        //See if the mouse is clicked and the brush is active to paint the
current px
if (isMousedown)
    setColor($(this));
})
.mouseup(function(){
    isMousedown = false;
});
//Colorize pixel
function setColor(obj){
obj.css({backgroundColor:'#000000'});
}
Thanks in advance,
Rob