diff --git a/IPython/html/static/notebook/js/keyboardmanager.js b/IPython/html/static/notebook/js/keyboardmanager.js
index 94068cd6a..0d6f35104 100644
--- a/IPython/html/static/notebook/js/keyboardmanager.js
+++ b/IPython/html/static/notebook/js/keyboardmanager.js
@@ -760,7 +760,7 @@ var IPython = (function (IPython) {
// focusout is called. In this case we bind to the remove event of jQueryUI,
// which gets triggered upon removal, iff it is focused at the time.
e.on('remove', function () {
- if (document.activeElement === e[0]) {
+ if (IPython.utils.is_focused(e[0])) {
console.log('kb remove');
that.enable();
}