Highlight <td> in table as dragging across?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • BaseballGraphs
    New Member
    • Sep 2010
    • 75

    Highlight <td> in table as dragging across?

    Hello,

    I am trying to find resources or an explanation on how to highlight several <td>'s within a table when a click is made and the mouse is dragged across the table while holding the click.

    Does anyone have any resources or examples on how to achieve this sort of functionality?

    Thanks!
  • Rabbit
    Recognized Expert MVP
    • Jan 2007
    • 12517

    #2
    Off the top of my head, you could use the mousedown of the td to log the origin td. And the mousemove of the td to log the end point. Then you would have the row and column of each point and you could change the background of each td with some loops.

    Comment

    • BaseballGraphs
      New Member
      • Sep 2010
      • 75

      #3
      Hi Rabbit,
      Thanks for your reply. After messing around for a while, I finally got it to work:
      Code:
      var down = false;
        $('table.weekly_schedule').mousedown( function(){
          down = true;
        } );
        $('table.weekly_schedule').mouseup( function(){
          down = false;
        } );
        $('table.weekly_schedule td.hour').mouseenter( function(){
          if ( ! down )
            return;
          $(this).trigger( 'mousedown' );
        } );

      Comment

      Working...