Javascript select cells in a table Lasso-style
<p>I'm really new to Javascript and I'm having trouble creating a Lasso - style table selection tool.    </p>

<p>Basically, I want to be able to drag the mouse over a table and have all the cells in that area get highlighted, so I can do something later with the selected cells.    </p>

<p>Here is a very buggy fiddle of what I am trying to achieve.   <a href="http://jsfiddle.net/kooldave98/ad5Z9/" rel="nofollow">http://jsfiddle.net/kooldave98/ad5Z9/</a></p>

<pre><code>var element = $("#rectangle");
// on mousedown
$(window).mousedown(function (e1) {
    // first move element on mouse location
    element.show().css({ top: e1.pageY, left: e1.pageX });
    // resize that div so it will be resizing while moouse is still pressed
    var resize = function (e2) {
        // you should check for direction in here and moves with top or left
        element.width(e2.pageX - e1.pageX);
        element.height(e2.pageY - e1.pageY);
    };
    $(window).mousemove(resize);
    // and finally unbind those functions when mouse click is released
    var unbind = function () {
        $(window).unbind(resize);
        $(window).unbind(unbind);
    };
    $(window).mouseup(unbind);
});
</code></pre>

<p>I need to be able to move the selection tool in any direction within the table and select additional cells afterwards using the "ctrl" key.</p>

<p>Any help will be greatly appreciated.</p>
