tags:

views:

104

answers:

1

Why i can't trigget handler via triggerHandler if it's was bound via live?

For example

  form.find('#code').live('change keyup',function(){
   process_code($(this));   
  });

Startups after window load:

   /* Triggers */
   if(checkCookie('banner_ready_code'))
   {
    $('#form').find('#code').triggerHandler('keyup');
   }

Nothing happens...

If i'm binding simply by .change or .keyup, triggerHandler is working properly as intended.

If it's bug, where to report it. Too lazy :) If not, please explain. :)

+1  A: 

Not a bug. triggerHandler() doesn't bubble the event, and live() relies on event bubbling since the handler is placed at the root of the DOM tree.

From live() docs: http://api.jquery.com/live/

The handler passed to .live() is never bound to an element; instead, .live() binds a special handler to the root of the DOM tree.

and

No handler is directly bound to the <div>, so the event bubbles up the DOM tree.

From triggerHandler() docs: http://api.jquery.com/triggerHandler/

Events created with .triggerHandler() do not bubble up the DOM hierarchy; if they are not handled by the target element directly, they do nothing.

patrick dw