Dave,

Thanks for the suggestion.  This is the direction I've gone in the past and
am using currently, but it can get pretty ugly with event delegation pretty
quickly on larger applications.  For example when you want to know which
mouse button was clicked, you need the actual event object to determine
"which".  In the past I've written a function to pass in an object and
override the event object values so that the handler can be called
programmatically and handle actual mouse events but it just seems like a lot
of work that could be resolved by having the ability to fire off a "native"
dom event that bubbles up so the handler function would be faster and
cleaner.  I've been using jQuery so long I don't know if this is even
possible with good old plain javascript.  If anyone has any suggestions
please post.

Cheers,
greenteam


dave.methvin wrote:
> 
> 
>> 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] ]);
> 
> 

-- 
View this message in context: 
http://www.nabble.com/Trigger-Dom-Event-tp19784821s27240p19803298.html
Sent from the jQuery General Discussion mailing list archive at Nabble.com.

Reply via email to