2014/06/20

jQuery delegate

$('body').delegate('*', 'focusin focusout', function(e){
    if ( e.type === 'focusin' ) {
        console.log('target: in ' + e.currentTarget.id);
    }
    else if ( e.type === 'focusout' ) {
        console.log('target: out ' + e.currentTarget.id);
    }
    e.stopPropagation();
    element.focus();
});

$('body').delegate('*'...) should be changed to $(document).delegate('body'...) - unproven
Then there should be $(document).undelegate('body'...)

No comments:

Post a Comment