Skip to content Skip to sidebar Skip to footer

Jquery Focusout Not Triggering On Exit Of Input Element

I'd like to fire the focusout event no matter where I click on the document. However i'm using a sortable list which each sortable item contains a textarea, the focusout event isn'

Solution 1:

You may try this

$("textarea").focusout(function(){
    alert("Do something");
}).click(function(e){
    e.stopPropagation();
    returntrue;
});

$("#draggable").draggable({
    start: function( event, ui ) {
        if( $('textarea:focus', this).length ){
            $('textarea', this).focusout();
        }
    }
}).click(function(e){
    if( $('textarea:focus', this).length ){
        $('textarea', this).focusout();
    }
});

DEMO.

Solution 2:

This works for me: http://jsfiddle.net/RWJhs/1/

$("textarea").focusout(function(){
    alert("Do something");
});

$('#draggable not(textarea)').on('click');
$("#draggable").draggable();

Edit: Triggering manually the blur event seems to make it work without disabling the draggin see here: http://jsfiddle.net/RWJhs/6/

$("#draggable").on('click', function(e){
    if (e.target == this && $('textarea').is(':focus')) $('textarea').blur();
});
$("textarea").blur(function(){
    alert("Do something");
});
$("#draggable").draggable();

Post a Comment for "Jquery Focusout Not Triggering On Exit Of Input Element"