diff --git a/IPython/html/static/notebook/js/outputarea.js b/IPython/html/static/notebook/js/outputarea.js
index 47f239f..79b902e 100644
--- a/IPython/html/static/notebook/js/outputarea.js
+++ b/IPython/html/static/notebook/js/outputarea.js
@@ -541,6 +541,10 @@ var IPython = (function (IPython) {
var container = element;
container.show = function(){console.log('Warning "container.show()" is deprecated.')};
// end backward compat
+
+ // Fix for ipython/issues/5293, make sure `element` is the area which
+ // output can be inserted into at the time of JS execution.
+ element = toinsert;
try {
eval(js);
} catch(err) {