By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,400 Members | 1,335 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,400 IT Pros & Developers. It's quick & easy.

Highlight <td> in table as dragging across?

P: 75
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!
Apr 13 '11 #1

✓ answered by BaseballGraphs

Hi Rabbit,
Thanks for your reply. After messing around for a while, I finally got it to work:
Expand|Select|Wrap|Line Numbers
  1. var down = false;
  2.   $('table.weekly_schedule').mousedown( function(){
  3.     down = true;
  4.   } );
  5.   $('table.weekly_schedule').mouseup( function(){
  6.     down = false;
  7.   } );
  8.   $('table.weekly_schedule td.hour').mouseenter( function(){
  9.     if ( ! down )
  10.       return;
  11.     $(this).trigger( 'mousedown' );
  12.   } );
  13.  

Share this Question
Share on Google+
2 Replies


Rabbit
Expert Mod 10K+
P: 12,430
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.
Apr 13 '11 #2

P: 75
Hi Rabbit,
Thanks for your reply. After messing around for a while, I finally got it to work:
Expand|Select|Wrap|Line Numbers
  1. var down = false;
  2.   $('table.weekly_schedule').mousedown( function(){
  3.     down = true;
  4.   } );
  5.   $('table.weekly_schedule').mouseup( function(){
  6.     down = false;
  7.   } );
  8.   $('table.weekly_schedule td.hour').mouseenter( function(){
  9.     if ( ! down )
  10.       return;
  11.     $(this).trigger( 'mousedown' );
  12.   } );
  13.  
Apr 14 '11 #3

Post your reply

Sign in to post your reply or Sign up for a free account.