views:

33

answers:

1

If I have a table with a lot of cells, lets assume 50 rows x 50 columns, is the application of a jquery "droppable" to each cell inefficient?

Can I assign the droppable to the parent TABLE, for instance, and then somehow capture the actual element (ie. the TD) where the item is dropped? If I remember my event delegation correctly, in any given event the TD recieves it first, followed by the TABLE.

Can someone please enlighten me?

Jason

+1  A: 

Yep you can do this using event delegation. Trying to listen for cliks on each TD tag would be a no no in terms of performance and would cause memory leak issues. Attach an event listener on the table tag and intercept the click event and determine which cell was clicked. Check this out, it talks using event delegation on a table to capture clicks on the TD elements:

http://www.sitepoint.com/blogs/2008/07/23/javascript-event-delegation-is-easier-than-you-think/

elduderino
This was very close, but it looks like I can't get event delegation to function in the way I want for the jQuery UI droppable feature. $(TABLE).droppable() appears to ignore the element actually clicked on and only returns the table itself as the event target. Oh well.
Jason
Hmm maybe it's a quirk of jquery droppables...ever considered implementing your own?Check this out:http://www.webreference.com/programming/javascript/mk/column2/
elduderino