Event Result
## jQuery event.result Property
The `event.result` property contains the return value of the last event handler function that was triggered by the specified event.
This property is highly useful when you have multiple event handlers bound to the same element for the same event, and you need to pass data or state from one handler to the next.
---
## Syntax
```javascript
event.result
```
### Parameter Values
| Parameter | Description |
| :--- | :--- |
| `event` | **Required.** The `event` object passed into the event handler function. |
---
## Code Examples
### Example 1: Basic Usage
The following example demonstrates how to return a value from the first `click` event handler and retrieve it in the second `click` event handler using `event.result`.
```javascript
// First click handler returns a string
$("button").click(function() {
return "Hello world!";
});
// Second click handler retrieves the returned value of the previous handler
$("button").click(function(event) {
$("p").html(event.result); // Displays "Hello world!" in the paragraph
});
```
### Example 2: Sequential Calculations
You can also use `event.result` to perform sequential operations or calculations across multiple event handlers.
```javascript
// First handler performs an initial calculation
$("div").click(function() {
return 10 + 5;
});
// Second handler takes the previous result and multiplies it
$("div").click(function(event) {
let finalResult = event.result * 2;
console.log("Final Result: " + finalResult); // Outputs: Final Result: 30
});
```
---
## Considerations and Best Practices
1. **Execution Order:** jQuery executes event handlers in the order they are bound. Therefore, `event.result` will only contain the return value of the handler that ran immediately before the current one.
2. **Undefined Results:** If the previous event handler does not explicitly return a value (or returns nothing), `event.result` will be `undefined`.
3. **Event Bubbling:** `event.result` is also preserved as the event bubbles up the DOM tree. If a child element's handler returns a value, the parent element's handler can access that value via `event.result`.
YouTip