forked from TobiaszCudnik/phpquery
-
Notifications
You must be signed in to change notification settings - Fork 66
Events
didier Belot edited this page Mar 6, 2018
·
2 revisions
pq('form')->bind('submit', 'submitHandler')->trigger('submit')->...
function submitHandler($e) {
print 'Target: '.$e->target->tagName;
print 'Bubbling ? '.$e->currentTarget->tagName;
}
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
none
- 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.
none
- 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.