event.dataS2C Home « Objects « event.data
Event object data property.
Description
The event.data Event object property, contains an optional data map passed to an event method when the currently executing handler is attached.
Syntax
| Signature | Description |
|---|---|
event.data | An optional data map passed to an event method when the currently executing handler is attached. |
Parameters
None.
Return
An Object object.
event.data ExampleTop
An optional data map passed to an event method when the currently executing handler is attached.
In the example below when we press the button we pass a map of data to the addText() function, which outputs a message below.
What we are doing here is passing across the event object to the function addText(event). The map we specify, in our case { param1: '#scrollspan2', param2: 'click was attached from .one()', param3: '**JavaScript event triggered** ' }
gets tagged onto the event.data property. We then access these parameter in the function via event.data.paramN and use it as part of the appended data.
$(function(){
$('form').one('click', '#btn2',
{ param1: '#scrollspan2', param2: 'click was attached from .one() ',
param3: '**JavaScript event triggered** ' }, addText);
function addText(event) {
$(event.data.param1).append(event.data.param2 + '<code>' + event.data.param3+ '</code>');
}
});
We will show a message here.