stopping a click event with another click event

stopping a click event with another click event


I would like to create a plugin that I can put before a click event on a button.  The click event should occur if the user's time on the page hasn't expired.  The plugin should check the user's time, and then stop the click event if the time has expired.  With the plugin, I'm essentially putting two click events on the same button, as I need to check the expiration when the button is clicked.  The plugin is working on my test page, but I'm afraid that this is contingent on an arbitrary ordering of the click events by jQuery.  If I have my click event chained after my plugin, can I be assured that the plugin would always stop the click event if the time is expired?  Or could jQuery execute the click event before the time gets checked?


(function( $ ){

      $.fn.checkExpiration = function(
    
            $this = $(this);
            return this.each(function(){
                $this.click(function(event){
                    if (timeExpired()){
                        event.stopImmediatePropagation(); // stop any further events bound to the element
                    }
                });          

            })    

      function timeExpired(){
            // return true if user's time has expired, else return false
      }


})( jQuery );

$(document).ready(function(){

      $("#my_button").checkExpiration().click(function(){

            // do this is if the user's time has not expired.

      });
}