How do I detect when a div has lost focus?

http://stackoverflow.com/questions/26303771/how-do-i-detect-when-a-div-has-lost-focus

by Meligy

HTML

<div class="editor">
    <input type="text"/>
    <input type="text"/>
</div>
<div class="editor">
    <input type="text"/>
    <input type="text"/>
</div>
<button>GO</button>

CSS

.loading {
    background: yellow;
}

JavaScript

$(".editor").on("focusout", function() {
    var $this = $(this);
    setTimeout(function() {
        $this.toggleClass("loading", !($this.find(":focus").length));        
    }, 0);
});