Is this what you want?
- EDITED -
Now you can select only straight lines (up or down). There may be a more elegant way to do all this, but I think it will work the way you want.
DEMO: http://jsfiddle.net/vrW2n/9/
// Add this variable var lastRow = 0;
In mousedown()
:
// This line gets the index of the first clicked row. lastRow = $(this).closest("tr")[0].rowIndex; active = true; $(".csstdhighlight").removeClass("csstdhighlight"); // clear previous selection //This is the big trick $(".temp_selected").removeClass("temp_selected"); ...
And in mousemove()
:
... var thisRow = $(this).closest("tr")[0].rowIndex; if( lastRow == thisRow || lastRow == thisRow - 1 || lastRow == thisRow + 1 ){ lastRow = $(this).closest("tr")[0].rowIndex; }else return;
source share