Wait for a user event [duplicate]
This question already has an answer here: How do I return the response from an asynchronous call? 36 answers I'm developing a javascript class (with jQuery) to create custom popup, but I can not figure out how to "pause" the script to wait for user response (click on the OK button or cancel) the class is like this: function Popup() { } Popup.Show = function(text) { var _response; /* code to draw the popup elements*/ $("#button-ok").on("click",function() { _response = "ok!" } return _response } if, for example, use it in an alert, the method always return "undefined", because it does not wait