[Solved] jQuery: How to return a value outside a function that contains the ‘this’?


I could be misunderstanding what you’re asking, but couldn’t you just call the other function from within the onSelect event handler?

Here’s a JSFiddle showing this in action, which I believe is doing what you need.

$("document").ready(function() {
    var timestamp;
    $("#startDate").datepicker({
        onSelect: function(e) { 
            var dateAsObject = $(this).datepicker( "getDate" ); 
            timestamp = dateAsObject.getTime(); 
            console.log("user selected: " + timestamp);
            otherFunction();
        }
    });

    function otherFunction() {
        console.log("test: " + timestamp);
    }
});

5

solved jQuery: How to return a value outside a function that contains the ‘this’?