i did the event delegation by hand and it's pretty easy.

("tbody").click(myHandler);

function myHandler(e) {
  var e = e || window.event;
  var elem = e.target || e.srcElement;
  if (elem.nodeName.toLowerCase() == "td") {
    // do stuff
  }
}

however, the jQuery "Listen" plugin is much more powerful, i recommend it
for event delegation since it will re-bind automatically to any newly
created elements. (this plugin superceeds the same author's "Intercept"
plugin)


Michael Geary wrote:
> 
> 
> If you have thousands of td's, that code is going to be very very slow. It
> makes an array of all the TD elements and then attaches an event handler
> to
> every one of them, one by one.
> 
> You would get *much* better performance by attaching a single event
> handler
> to the table itself, then using event.target in the event handler to
> reference the cell that was clicked.
> 
> -Mike
> 
>> From: pedalpete
>> 
>> I'm not sure exactly what you are trying to do, but I think 
>> binding each cell to an external function, or creating an 
>> 'anonymous' function inline maybe isn't the best way to go.
>> 
>> I have a table with lots of cells, and when the user clicks 
>> on a cell, i pass the id of that cell to a script. It's 
>> fairly easy, and i think much more efficient than what you 
>> are suggesting (but I don't exactly understand what you are 
>> trying to do).
>> 
>> Here's the basics of how my script works [code] 
>> $("td").click(function(){
>>       var id = this.id;
>> 
>> }
> 
> 
> 

-- 
View this message in context: 
http://www.nabble.com/bind%28%29-and-thousands-of-%3Ctd%3E-elements---inline-or-extrnal--tp16352984s27240p16392853.html
Sent from the jQuery General Discussion mailing list archive at Nabble.com.

Reply via email to