Referring to the code below, is there a way to bind the “test 2” handler to the “my_event” event after “my_event” has occurred so that “test 2” is run right away?
<!DOCTYPE html>
<html>
<head>
<title>tests</title>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.7.1.min.js"></script>
</head>
<body>
<script type="text/javascript">
$(document).bind("my_event", function () {
alert("test 1");
});
$(document).trigger("my_event");
$(document).bind("my_event", function () {
alert("test 2");
});
</script>
</body>
</html>
Checkout jQuery’s special events. Anytime a
"facebookReady"event is added, theaddcallback will be called, and you can chose to invoke the callback immediately or defer it based on some condition. In this example, I’m looking at the presence of the globalFBproperty to decide whether to invoke it.Once the special event’s callback is setup, bind the event as you normally would.
Depending on whether FB has loaded on not, it may or may not trigger immediately.
Checkout an example.