Search code examples
jqueryeventshandsontable

Why is focusout event not triggering in jQuery with focusout method ?


I'm using handsontable jQuery plugin. I'm trying to intercept when a user stops editing a cell. When you double click on a cell, a text area with class handsontableInput appears on the position of that cell.

Using jQuery I tried to get the callback whenever the user clicks elsewhere, thus loosing focus of the textarea.

Here is the simple focusout code:

$(".handsontableInput").focusout(function () {
    alert("LLL");
});

Here is my fiddle.

Also, would this work if the page with the handsontable was in a frame, and I clicked outside the frame?

Thank you


Solution

  • You should use the .on method:

    $("#exampleGrid").on('focusout','.handsontableInput',function () {
        alert("LLL");
    });
    

    JSFIDDLE: http://jsfiddle.net/edi9999/HEH5C/1/

    The issue with your code was that at the moment of the execution of $(".handsontableInput"), they was no element with this class, so the event was attached to no element.