jQuery event.result Property



The jQuery event.result property is used to retrieve the last or previous value returned by an event handler triggered by the specified event.

This property contains the value that was returned by the previous event handler for the same event. If the previous handler did not return any value, the event.result will be undefined.

Syntax

Following is the syntax of the jQuery event.result property −

event.result

Parameters

This property does not accept any parameter.

Return Value

This property returns the last or previous value returned by an event handler.

Example 1

The following is the basic example of the jQuery event.result property −

<!DOCTYPE html>
<html>
<head>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7/jquery.min.js"></script>
</head>
<body>
    <p>Click on the below button to see the event result</p>
    <button>Click me!</button>
    <script>
        $('button').click(function(){
            return "TutorialsPoint";
        });
        $('button').click(function(event){
            alert("Eevnt result: " + event.result);
        })
    </script>
</body>
</html>

Output

The above program displays a button, and when the button is clicked, a pop-up alert appears displaying the event result on the browser screen −


When the button is clicked −


Example 2

The following is another example of the jQuery event.result property. We use this property to retrieve the return value of the event handler that was triggered by the specified element −

<!DOCTYPE html>
<html>
<head>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7/jquery.min.js"></script>
    <style>
        button{
            background-color: green;
            color: white;
            padding: 10px
        }
        span{
            color: green;
            font-weight: bold;
        }
    </style>
</head>
<body>
    <p>Click on the below button to see the event result</p>
    <button>Click to see event result</button>
    <span></span>
    <script>
        $('button').click(function(){
            return "Welcome to TP";
        });
        $('button').click(function(event){
            $('span').text("Eevnt result: " + event.result);
        })
    </script>
</body>
</html>

Output

After executing the above program, it displays a button, when it is clicked the event result will be displayed next to it −


When the button is clicked −


Example 3

If the previous event handler does not return any value, the event.result will be undefined

<!DOCTYPE html>
<html>
<head>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7/jquery.min.js"></script>
</head>
<body>
    <p>Click on the below button to see the event result</p>
    <button>Click</button>
    <span></span>
    <script>
        $('button').click(function(){
            return;
        });
        $('button').click(function(event){
            $('span').text("Eevnt result: " + event.result);
        })
    </script>
</body>
</html>

Output

The above program returns undefined as a result −


jquery_ref_events.htm
Advertisements