Andrew Bullock
Andrew Bullock

Reputation: 37406

How to get at event when overriding jquery event handlers

I have the following code:

var oldFocus = $.fn.focus;
$.fn.focus = function () {
    // how to get event here?
    return oldFocus.apply(this, arguments);
};

how can I get at the event object?

Update: using jquery 2.0.3

Upvotes: 1

Views: 66

Answers (1)

pushOk
pushOk

Reputation: 290

$.event.special.focus = {
    trigger: function(e){
        console.log(e);
        return false; // if false, focus is not firing
    }
};

Try this code.

Edit by OP:

pushOK's code is the starting point i needed. What i needed to achieve my objective detailed in the comments below was:

$.event.special.focus = {
    trigger: function(e){
        e.preventDefault();
        return true;
    }
};

Upvotes: 1

Related Questions