> I'm having problems with jQuery events and event delegation.  I've got a
> table with multiple rows and a click event registered on the tbody of that
> table.  I'm trying to programmatically "click" a cell so that the event will
> bubble up to the tbody click event with the correct target.  

I had this same dilemma earlier in the week. You're right that
triggered clicks don't bubble, and if you try to trigger a click on
the tbody then e.target is the tbody and not the fake-clicked element.
What I did was pass an optional argument to the tbody click handler
that has the target element for programmatic clicks and overrides
e.target:

$("#mytable tbody").click(function(e, tgt){
   var $clicked = $(tgt || e.target);
   // do something to this element
});

// trigger a click on the first td in the table's tbody
$("#mytable tbody").trigger("click", [ $("#mytable tbody td:first")
[0] ]);

Reply via email to