Question

I have these bits of code that are supposed to bug two functions and fire events for them. For some reason, however, the event does not seem to trigger. They log to the console as expected, but the event never gets fired.

//Show backstage event
(function( $, oldRem ){
    backstage.show = function(){
        console.log("yup, I'm the right one");
        var resp = oldRem.apply( this, arguments );
        $("#backstageArea").trigger("showBackstage");
        return(resp);
    };
})( jQuery, backstage.show );
//Hide backstage event
(function( $, oldRem ){
    backstage.hide = function(){
        console.log("And so am I.");
        var resp = oldRem.apply( this, arguments );
        if(anim && config.chkAnimate) {setTimeout( 'jQuery("#backstageArea").trigger("hideBackstage")', config.animDuration);}
        else {$("#backstageArea").trigger("hideBackstage");}
        return(resp);
    };
})( jQuery, backstage.hide );

//Resize never logs its console message.
jQuery.bind("hideBackstage", function(){topbar.resize();});
jQuery.bind("showBackstage", function(){topbar.resize();});
Was it helpful?

Solution

You need to specify what element(s) to bind to, so try:

jQuery("#backstageArea").bind(...

instead of

jQuery.bind(...

(And if you're using jQuery version 1.7+ you may like to switch to the .on() method - will have the same effect for this purpose, but is the recommended way of doing things from v1.7 on.)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top