Skip to content

Latest commit

 

History

History
47 lines (38 loc) · 2.92 KB

Events.md

File metadata and controls

47 lines (38 loc) · 2.92 KB

Table of Contents

Example

pq('form')->bind('submit', 'submitHandler')->trigger('submit')->...
function submitHandler($e) {
  print 'Target: '.$e->target->tagName;
  print 'Bubbling ? '.$e->currentTarget->tagName;
}

Server Side Events

phpQuery support server-side events, same as jQuery handle client-side ones. On server there isn't, of course, events such as mouseover (but they can be triggered).

By default, phpQuery automatically fires up only change event for form elements. If you load WebBrowser plugin, submit and click will be handled properly - eg submitting form with inputs' data to action URL via new Ajax request.

$this (this in JS) context for handler scope isn't available. You have to use one of following manually:

  • $event->target
  • $event->currentTarget
  • $event->relatedTarget

Page Load

none

Event Handling

  • bind($type, $data, $fn) Binds a handler to one or more events (like click) for each matched element. Can also bind custom events.
  • one($type, $data, $fn) Binds a handler to one or more events to be executed once for each matched element.
  • trigger($type , $data ) Trigger a type of event on every matched element.
  • triggerHandler($type , $data ) This particular method triggers all bound event handlers on an element (for a specific event type) WITHOUT executing the browsers default actions.
  • unbind($type , $data ) This does the opposite of bind, it removes bound events from each of the matched elements.

Interaction Helpers

none

Event Helpers

  • change() Triggers the change event of each matched element.
  • change($fn) Binds a function to the change event of each matched element.
  • submit() Trigger the submit event of each matched element.
  • submit($fn) Bind a function to the submit event of each matched element.

Read more at Events section on jQuery Documentation Site.