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;
        onSelect: function(e) { 
            var dateAsObject = $(this).datepicker( "getDate" ); 
            timestamp = dateAsObject.getTime(); 
            console.log("user selected: " + timestamp);

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

Browse More Popular Posts

Leave a Comment